blob: 8e21e114b9231500d441d61d976d1bac47b25501 [file] [log] [blame]
Mark Slee83c52a82006-06-07 06:51:18 +00001package com.facebook.thrift.server;
2
3import com.facebook.thrift.TProcessor;
Mark Slee456b7a82006-10-25 20:53:37 +00004import com.facebook.thrift.protocol.TBinaryProtocol;
5import com.facebook.thrift.protocol.TProtocolFactory;
Mark Sleed788b2e2006-09-07 01:26:35 +00006import com.facebook.thrift.transport.TServerTransport;
7import com.facebook.thrift.transport.TTransportFactory;
Mark Slee83c52a82006-06-07 06:51:18 +00008
9/**
10 * Generic interface for a Thrift server.
11 *
12 * @author Mark Slee <mcslee@facebook.com>
13 */
14public abstract class TServer {
15
16 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000017 * Core processor
18 */
Mark Slee83c52a82006-06-07 06:51:18 +000019 protected TProcessor processor_;
20
Mark Sleed788b2e2006-09-07 01:26:35 +000021 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000022 * Server transport
Mark Sleeffcddd62006-09-06 20:37:03 +000023 */
Mark Sleed788b2e2006-09-07 01:26:35 +000024 protected TServerTransport serverTransport_;
Mark Sleeffcddd62006-09-06 20:37:03 +000025
26 /**
Aditya Agarwal5a429582007-02-06 02:51:15 +000027 * Input Transport Factory
Mark Slee83c52a82006-06-07 06:51:18 +000028 */
Aditya Agarwal5a429582007-02-06 02:51:15 +000029 protected TTransportFactory inputTransportFactory_;
Mark Sleed788b2e2006-09-07 01:26:35 +000030
31 /**
Aditya Agarwal5a429582007-02-06 02:51:15 +000032 * Output Transport Factory
Mark Slee456b7a82006-10-25 20:53:37 +000033 */
Aditya Agarwal5a429582007-02-06 02:51:15 +000034 protected TTransportFactory outputTransportFactory_;
35
36 /**
37 * Input Protocol Factory
38 */
39 protected TProtocolFactory inputProtocolFactory_;
40
41 /**
42 * Output Protocol Factory
43 */
44 protected TProtocolFactory outputProtocolFactory_;
Mark Slee456b7a82006-10-25 20:53:37 +000045
46 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000047 * Default constructors.
48 */
49
50 protected TServer(TProcessor processor,
51 TServerTransport serverTransport) {
52 this(processor,
Aditya Agarwal5a429582007-02-06 02:51:15 +000053 serverTransport,
Mark Slee456b7a82006-10-25 20:53:37 +000054 new TTransportFactory(),
Aditya Agarwal5a429582007-02-06 02:51:15 +000055 new TTransportFactory(),
56 new TBinaryProtocol.Factory(),
Mark Slee456b7a82006-10-25 20:53:37 +000057 new TBinaryProtocol.Factory());
Mark Sleed788b2e2006-09-07 01:26:35 +000058 }
59
60 protected TServer(TProcessor processor,
61 TServerTransport serverTransport,
62 TTransportFactory transportFactory) {
63 this(processor,
64 serverTransport,
65 transportFactory,
Aditya Agarwal5a429582007-02-06 02:51:15 +000066 transportFactory,
67 new TBinaryProtocol.Factory(),
Mark Slee456b7a82006-10-25 20:53:37 +000068 new TBinaryProtocol.Factory());
Mark Sleed788b2e2006-09-07 01:26:35 +000069 }
70
71 protected TServer(TProcessor processor,
72 TServerTransport serverTransport,
73 TTransportFactory transportFactory,
Mark Slee456b7a82006-10-25 20:53:37 +000074 TProtocolFactory protocolFactory) {
Aditya Agarwal5a429582007-02-06 02:51:15 +000075 this(processor,
76 serverTransport,
77 transportFactory,
78 transportFactory,
79 protocolFactory,
80 protocolFactory);
81 }
82
83 protected TServer(TProcessor processor,
84 TServerTransport serverTransport,
85 TTransportFactory inputTransportFactory,
86 TTransportFactory outputTransportFactory,
87 TProtocolFactory inputProtocolFactory,
88 TProtocolFactory outputProtocolFactory) {
Mark Slee83c52a82006-06-07 06:51:18 +000089 processor_ = processor;
Mark Sleed788b2e2006-09-07 01:26:35 +000090 serverTransport_ = serverTransport;
Aditya Agarwal5a429582007-02-06 02:51:15 +000091 inputTransportFactory_ = inputTransportFactory;
92 outputTransportFactory_ = outputTransportFactory;
93 inputProtocolFactory_ = inputProtocolFactory;
94 outputProtocolFactory_ = outputProtocolFactory;
Mark Slee83c52a82006-06-07 06:51:18 +000095 }
96
97 /**
98 * The run method fires up the server and gets things going.
99 */
Mark Slee4e755ca2006-09-12 00:46:08 +0000100 public abstract void serve();
Mark Slee456b7a82006-10-25 20:53:37 +0000101
Mark Slee83c52a82006-06-07 06:51:18 +0000102}