blob: 2ac322aecbc6e9aa9d1da733b562921b870c8409 [file] [log] [blame]
Mark Slee7eb0d632007-03-01 00:00:27 +00001// Copyright (c) 2006- Facebook
2// Distributed under the Thrift Software License
3//
4// See accompanying file LICENSE or visit the Thrift site at:
5// http://developers.facebook.com/thrift/
6
Mark Slee83c52a82006-06-07 06:51:18 +00007package com.facebook.thrift.server;
8
Mark Slee448849d2007-05-31 01:30:22 +00009import com.facebook.thrift.TProcessorFactory;
Mark Slee456b7a82006-10-25 20:53:37 +000010import com.facebook.thrift.protocol.TBinaryProtocol;
11import com.facebook.thrift.protocol.TProtocolFactory;
Mark Sleed788b2e2006-09-07 01:26:35 +000012import com.facebook.thrift.transport.TServerTransport;
13import com.facebook.thrift.transport.TTransportFactory;
Mark Slee83c52a82006-06-07 06:51:18 +000014
15/**
16 * Generic interface for a Thrift server.
17 *
18 * @author Mark Slee <mcslee@facebook.com>
19 */
20public abstract class TServer {
21
22 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000023 * Core processor
24 */
Mark Slee448849d2007-05-31 01:30:22 +000025 protected TProcessorFactory processorFactory_;
Mark Slee83c52a82006-06-07 06:51:18 +000026
Mark Sleed788b2e2006-09-07 01:26:35 +000027 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000028 * Server transport
Mark Sleeffcddd62006-09-06 20:37:03 +000029 */
Mark Sleed788b2e2006-09-07 01:26:35 +000030 protected TServerTransport serverTransport_;
Mark Sleeffcddd62006-09-06 20:37:03 +000031
32 /**
Aditya Agarwal5a429582007-02-06 02:51:15 +000033 * Input Transport Factory
Mark Slee83c52a82006-06-07 06:51:18 +000034 */
Aditya Agarwal5a429582007-02-06 02:51:15 +000035 protected TTransportFactory inputTransportFactory_;
Mark Sleed788b2e2006-09-07 01:26:35 +000036
37 /**
Aditya Agarwal5a429582007-02-06 02:51:15 +000038 * Output Transport Factory
Mark Slee456b7a82006-10-25 20:53:37 +000039 */
Aditya Agarwal5a429582007-02-06 02:51:15 +000040 protected TTransportFactory outputTransportFactory_;
41
42 /**
43 * Input Protocol Factory
44 */
45 protected TProtocolFactory inputProtocolFactory_;
46
47 /**
48 * Output Protocol Factory
49 */
50 protected TProtocolFactory outputProtocolFactory_;
Mark Slee456b7a82006-10-25 20:53:37 +000051
52 /**
Mark Sleed788b2e2006-09-07 01:26:35 +000053 * Default constructors.
54 */
55
Mark Slee448849d2007-05-31 01:30:22 +000056 protected TServer(TProcessorFactory processorFactory,
Mark Sleed788b2e2006-09-07 01:26:35 +000057 TServerTransport serverTransport) {
Mark Slee448849d2007-05-31 01:30:22 +000058 this(processorFactory,
Aditya Agarwal5a429582007-02-06 02:51:15 +000059 serverTransport,
Mark Slee456b7a82006-10-25 20:53:37 +000060 new TTransportFactory(),
Aditya Agarwal5a429582007-02-06 02:51:15 +000061 new TTransportFactory(),
62 new TBinaryProtocol.Factory(),
Mark Slee456b7a82006-10-25 20:53:37 +000063 new TBinaryProtocol.Factory());
Mark Sleed788b2e2006-09-07 01:26:35 +000064 }
65
Mark Slee448849d2007-05-31 01:30:22 +000066 protected TServer(TProcessorFactory processorFactory,
Mark Sleed788b2e2006-09-07 01:26:35 +000067 TServerTransport serverTransport,
68 TTransportFactory transportFactory) {
Mark Slee448849d2007-05-31 01:30:22 +000069 this(processorFactory,
Mark Sleed788b2e2006-09-07 01:26:35 +000070 serverTransport,
71 transportFactory,
Aditya Agarwal5a429582007-02-06 02:51:15 +000072 transportFactory,
73 new TBinaryProtocol.Factory(),
Mark Slee456b7a82006-10-25 20:53:37 +000074 new TBinaryProtocol.Factory());
Mark Sleed788b2e2006-09-07 01:26:35 +000075 }
76
Mark Slee448849d2007-05-31 01:30:22 +000077 protected TServer(TProcessorFactory processorFactory,
Mark Sleed788b2e2006-09-07 01:26:35 +000078 TServerTransport serverTransport,
79 TTransportFactory transportFactory,
Mark Slee456b7a82006-10-25 20:53:37 +000080 TProtocolFactory protocolFactory) {
Mark Slee448849d2007-05-31 01:30:22 +000081 this(processorFactory,
Aditya Agarwal5a429582007-02-06 02:51:15 +000082 serverTransport,
83 transportFactory,
84 transportFactory,
85 protocolFactory,
86 protocolFactory);
87 }
88
Mark Slee448849d2007-05-31 01:30:22 +000089 protected TServer(TProcessorFactory processorFactory,
Aditya Agarwal5a429582007-02-06 02:51:15 +000090 TServerTransport serverTransport,
91 TTransportFactory inputTransportFactory,
92 TTransportFactory outputTransportFactory,
93 TProtocolFactory inputProtocolFactory,
94 TProtocolFactory outputProtocolFactory) {
Mark Slee448849d2007-05-31 01:30:22 +000095 processorFactory_ = processorFactory;
Mark Sleed788b2e2006-09-07 01:26:35 +000096 serverTransport_ = serverTransport;
Aditya Agarwal5a429582007-02-06 02:51:15 +000097 inputTransportFactory_ = inputTransportFactory;
98 outputTransportFactory_ = outputTransportFactory;
99 inputProtocolFactory_ = inputProtocolFactory;
100 outputProtocolFactory_ = outputProtocolFactory;
Mark Slee83c52a82006-06-07 06:51:18 +0000101 }
102
103 /**
104 * The run method fires up the server and gets things going.
105 */
Mark Slee4e755ca2006-09-12 00:46:08 +0000106 public abstract void serve();
Mark Slee456b7a82006-10-25 20:53:37 +0000107
Mark Slee0502e612007-11-03 05:30:32 +0000108 /**
109 * Stop the server. This is optional on a per-implementation basis. Not
110 * all servers are required to be cleanly stoppable.
111 */
112 public void stop() {}
113
Mark Slee83c52a82006-06-07 06:51:18 +0000114}