THRIFT-951. java: Add a new isServing() method to TServer

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1021941 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bryan Duxbury 2010-10-12 22:32:23 +00:00
parent 21cd3180ef
commit 4c5689269f
5 changed files with 36 additions and 16 deletions

View File

@ -237,11 +237,15 @@ public class THsHaServer extends TNonblockingServer {
return;
}
setServing(true);
// this will block while we serve
joinSelector();
gracefullyShutdownInvokerPool();
setServing(false);
// do a little cleanup
stopListening();

View File

@ -178,9 +178,13 @@ public class TNonblockingServer extends TServer {
return;
}
setServing(true);
// this will block while we serve
joinSelector();
setServing(false);
// do a little cleanup
stopListening();
}

View File

@ -61,6 +61,8 @@ public abstract class TServer {
*/
protected TProtocolFactory outputProtocolFactory_;
private boolean isServing;
/**
* Default constructors.
*/
@ -123,4 +125,11 @@ public abstract class TServer {
*/
public void stop() {}
public boolean isServing() {
return isServing;
}
protected void setServing(boolean serving) {
isServing = serving;
}
}

View File

@ -26,9 +26,8 @@ import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportFactory;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TTransportFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -98,6 +97,8 @@ public class TSimpleServer extends TServer {
return;
}
setServing(true);
while (!stopped_) {
TTransport client = null;
TProcessor processor = null;
@ -136,6 +137,7 @@ public class TSimpleServer extends TServer {
}
}
setServing(false);
}
public void stop() {

View File

@ -19,26 +19,25 @@
package org.apache.thrift.server;
import org.apache.thrift.TException;
import org.apache.thrift.TProcessor;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TTransportFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.thrift.TException;
import org.apache.thrift.TProcessor;
import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TTransportFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Server which uses Java's built in ThreadPool management to spawn off
@ -178,6 +177,7 @@ public class TThreadPoolServer extends TServer {
}
stopped_ = false;
setServing(true);
while (!stopped_) {
int failureCount = 0;
try {
@ -210,6 +210,7 @@ public class TThreadPoolServer extends TServer {
now = newnow;
}
}
setServing(false);
}
public void stop() {