本文整理匯總了Java中org.apache.thrift.server.TServer.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java TServer.stop方法的具體用法?Java TServer.stop怎麽用?Java TServer.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.thrift.server.TServer
的用法示例。
在下文中一共展示了TServer.stop方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
TMultiplexedProcessor proc = new TMultiplexedProcessor();
proc.registerProcessor("Message", new Message.Processor<>(new MessageHandler()));
proc.registerProcessor("ServerTime", new ServerTime.Processor<>(new ServerTimeHandler()));
TServer server = new TThreadedSelectorServer(
new TThreadedSelectorServer.Args(trans_svr)
.processor(proc)
.protocolFactory(new TJSONProtocol.Factory())
.workerThreads(6)
.selectorThreads(3));
Thread server_thread = new Thread(new RunnableServer(server), "server_thread");
server_thread.start();
System.out.println("[Server] press enter to shutdown> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
System.out.println("[Server] shutting down...");
server.stop();
server_thread.join();
System.out.println("[Server] down, exiting");
}
示例2: stop
import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public synchronized void stop() {
final TServer thriftServer = this.thriftServer;
if (thriftServer != null) {
this.service.stop();
thriftServer.stop();
final ThreadPoolExecutor connExecutor = this.thriftThreadPerConnExecutor;
if (connExecutor != null) {
connExecutor.shutdown();
}
this.thriftExecutor.shutdown();
try {
this.thriftMainThread.join(5000L);
// force stop the executor if required
if (this.thriftMainThread.isAlive()) {
if (connExecutor != null) {
connExecutor.shutdownNow();
}
this.thriftExecutor.shutdownNow();
this.thriftMainThread.join();
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
}
示例3: testProcessor
import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
throws Exception
{
try (TServerSocket serverTransport = new TServerSocket(0)) {
TProtocolFactory protocolFactory = new Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory();
TServer server = new TSimpleServer(new Args(serverTransport)
.protocolFactory(protocolFactory)
.transportFactory(transportFactory)
.processor(processor));
Thread serverThread = new Thread(server::serve);
try {
serverThread.start();
int localPort = serverTransport.getServerSocket().getLocalPort();
HostAndPort address = HostAndPort.fromParts("localhost", localPort);
int sum = 0;
for (ToIntFunction<HostAndPort> client : clients) {
sum += client.applyAsInt(address);
}
return sum;
}
finally {
server.stop();
serverThread.interrupt();
}
}
}
示例4: testProcessor
import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
throws Exception
{
try (TServerSocket serverTransport = new TServerSocket(0)) {
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory();
TServer server = new TSimpleServer(new Args(serverTransport)
.protocolFactory(protocolFactory)
.transportFactory(transportFactory)
.processor(processor));
Thread serverThread = new Thread(server::serve);
try {
serverThread.start();
int localPort = serverTransport.getServerSocket().getLocalPort();
HostAndPort address = HostAndPort.fromParts("localhost", localPort);
int sum = 0;
for (ToIntFunction<HostAndPort> client : clients) {
sum += client.applyAsInt(address);
}
return sum;
}
finally {
server.stop();
serverThread.interrupt();
}
}
}
示例5: shutdown
import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
/**
* Shutdown all the running servers
*/
public void shutdown() {
for (TServer server : thriftServers) {
server.stop();
}
try {
zookeeper.shutdown();
discovery.close();
} catch (IOException ex) {
//don't care
}
}
示例6: stopAllServers
import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
/**
* 關閉所有thrift服務的方法
*/
protected void stopAllServers() {
for (TServer tServer : servers) {
tServer.stop();
}
}