blob: 3cae00b6064fe98cc067115f9bb89a7220be359e [file] [log] [blame]
Mark Slee83c52a82006-06-07 06:51:18 +00001package com.facebook.thrift.server;
2
3import com.facebook.thrift.TProcessor;
Mark Sleed788b2e2006-09-07 01:26:35 +00004import com.facebook.thrift.transport.TServerTransport;
5import com.facebook.thrift.transport.TTransportFactory;
6import com.facebook.thrift.transport.TBaseTransportFactory;
Mark Slee83c52a82006-06-07 06:51:18 +00007
8/**
9 * Generic interface for a Thrift server.
10 *
11 * @author Mark Slee <mcslee@facebook.com>
12 */
13public abstract class TServer {
14
15 /**
16 * The options class should be subclassed by particular servers which have
17 * specific options needs, while the general options should live here.
18 */
19 public static class Options {
20 public Options() {}
21 }
22
Mark Sleed788b2e2006-09-07 01:26:35 +000023 /**
24 * Core processor
25 */
Mark Slee83c52a82006-06-07 06:51:18 +000026 protected TProcessor processor_;
27
Mark Sleed788b2e2006-09-07 01:26:35 +000028 /**
29 * Server options
30 */
Mark Slee83c52a82006-06-07 06:51:18 +000031 protected Options options_;
32
33 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000034 * Server transport
Mark Sleeffcddd62006-09-06 20:37:03 +000035 */
Mark Sleed788b2e2006-09-07 01:26:35 +000036 protected TServerTransport serverTransport_;
Mark Sleeffcddd62006-09-06 20:37:03 +000037
38 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000039 * Transport Factory
Mark Slee83c52a82006-06-07 06:51:18 +000040 */
Mark Sleed788b2e2006-09-07 01:26:35 +000041 protected TTransportFactory transportFactory_;
42
43 /**
44 * Default constructors.
45 */
46
47 protected TServer(TProcessor processor,
48 TServerTransport serverTransport) {
49 this(processor,
50 serverTransport,
51 new TBaseTransportFactory(),
52 new Options());
53 }
54
55 protected TServer(TProcessor processor,
56 TServerTransport serverTransport,
57 TTransportFactory transportFactory) {
58 this(processor,
59 serverTransport,
60 transportFactory,
61 new Options());
62 }
63
64
65 protected TServer(TProcessor processor,
66 TServerTransport serverTransport,
67 Options options) {
68 this(processor,
69 serverTransport,
70 new TBaseTransportFactory(),
71 options);
72 }
73
74 protected TServer(TProcessor processor,
75 TServerTransport serverTransport,
76 TTransportFactory transportFactory,
77 Options options) {
Mark Slee83c52a82006-06-07 06:51:18 +000078 processor_ = processor;
Mark Sleed788b2e2006-09-07 01:26:35 +000079 serverTransport_ = serverTransport;
80 transportFactory_ = transportFactory;
Mark Slee83c52a82006-06-07 06:51:18 +000081 options_ = options;
82 }
83
84 /**
85 * The run method fires up the server and gets things going.
86 */
Mark Slee4e755ca2006-09-12 00:46:08 +000087 public abstract void serve();
Mark Slee83c52a82006-06-07 06:51:18 +000088}