]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/src/org/apache/thrift/server/TServer.java
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / java / src / org / apache / thrift / server / TServer.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.thrift.server;
21
22 import org.apache.thrift.TProcessor;
23 import org.apache.thrift.TProcessorFactory;
24 import org.apache.thrift.protocol.TBinaryProtocol;
25 import org.apache.thrift.protocol.TProtocolFactory;
26 import org.apache.thrift.transport.TServerTransport;
27 import org.apache.thrift.transport.TTransportFactory;
28
29 /**
30 * Generic interface for a Thrift server.
31 *
32 */
33 public abstract class TServer {
34
35 public static class Args extends AbstractServerArgs<Args> {
36 public Args(TServerTransport transport) {
37 super(transport);
38 }
39 }
40
41 public static abstract class AbstractServerArgs<T extends AbstractServerArgs<T>> {
42 final TServerTransport serverTransport;
43 TProcessorFactory processorFactory;
44 TTransportFactory inputTransportFactory = new TTransportFactory();
45 TTransportFactory outputTransportFactory = new TTransportFactory();
46 TProtocolFactory inputProtocolFactory = new TBinaryProtocol.Factory();
47 TProtocolFactory outputProtocolFactory = new TBinaryProtocol.Factory();
48
49 public AbstractServerArgs(TServerTransport transport) {
50 serverTransport = transport;
51 }
52
53 public T processorFactory(TProcessorFactory factory) {
54 this.processorFactory = factory;
55 return (T) this;
56 }
57
58 public T processor(TProcessor processor) {
59 this.processorFactory = new TProcessorFactory(processor);
60 return (T) this;
61 }
62
63 public T transportFactory(TTransportFactory factory) {
64 this.inputTransportFactory = factory;
65 this.outputTransportFactory = factory;
66 return (T) this;
67 }
68
69 public T inputTransportFactory(TTransportFactory factory) {
70 this.inputTransportFactory = factory;
71 return (T) this;
72 }
73
74 public T outputTransportFactory(TTransportFactory factory) {
75 this.outputTransportFactory = factory;
76 return (T) this;
77 }
78
79 public T protocolFactory(TProtocolFactory factory) {
80 this.inputProtocolFactory = factory;
81 this.outputProtocolFactory = factory;
82 return (T) this;
83 }
84
85 public T inputProtocolFactory(TProtocolFactory factory) {
86 this.inputProtocolFactory = factory;
87 return (T) this;
88 }
89
90 public T outputProtocolFactory(TProtocolFactory factory) {
91 this.outputProtocolFactory = factory;
92 return (T) this;
93 }
94 }
95
96 /**
97 * Core processor
98 */
99 protected TProcessorFactory processorFactory_;
100
101 /**
102 * Server transport
103 */
104 protected TServerTransport serverTransport_;
105
106 /**
107 * Input Transport Factory
108 */
109 protected TTransportFactory inputTransportFactory_;
110
111 /**
112 * Output Transport Factory
113 */
114 protected TTransportFactory outputTransportFactory_;
115
116 /**
117 * Input Protocol Factory
118 */
119 protected TProtocolFactory inputProtocolFactory_;
120
121 /**
122 * Output Protocol Factory
123 */
124 protected TProtocolFactory outputProtocolFactory_;
125
126 private volatile boolean isServing;
127
128 protected TServerEventHandler eventHandler_;
129
130 // Flag for stopping the server
131 // Please see THRIFT-1795 for the usage of this flag
132 protected volatile boolean stopped_ = false;
133
134 protected TServer(AbstractServerArgs args) {
135 processorFactory_ = args.processorFactory;
136 serverTransport_ = args.serverTransport;
137 inputTransportFactory_ = args.inputTransportFactory;
138 outputTransportFactory_ = args.outputTransportFactory;
139 inputProtocolFactory_ = args.inputProtocolFactory;
140 outputProtocolFactory_ = args.outputProtocolFactory;
141 }
142
143 /**
144 * The run method fires up the server and gets things going.
145 */
146 public abstract void serve();
147
148 /**
149 * Stop the server. This is optional on a per-implementation basis. Not
150 * all servers are required to be cleanly stoppable.
151 */
152 public void stop() {}
153
154 public boolean isServing() {
155 return isServing;
156 }
157
158 protected void setServing(boolean serving) {
159 isServing = serving;
160 }
161
162 public void setServerEventHandler(TServerEventHandler eventHandler) {
163 eventHandler_ = eventHandler;
164 }
165
166 public TServerEventHandler getEventHandler() {
167 return eventHandler_;
168 }
169
170 public boolean getShouldStop() {
171 return this.stopped_;
172 }
173
174 public void setShouldStop(boolean shouldStop) {
175 this.stopped_ = shouldStop;
176 }
177 }