- java.lang.Object
 - 
- com.pervasive.datarush.commons.util.GenericTCPServer
 
 
- 
public final class GenericTCPServer extends Object
General purpose TCP server that provides thread pooling, start and stop code. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGenericTCPServer.ConnectionHandlerHandles incomming connectionsclassGenericTCPServer.ServerContextInformation passed to a server implementation to provide execution context. 
- 
Constructor Summary
Constructors Constructor Description GenericTCPServer(GenericTCPServer.ConnectionHandler handler)Creates a new server 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawaitShutdown(long timeout, TimeUnit unit)Waits for pending requests to finish.voiddisableThreadPooling()Disables thread pooling of workers.GenericTCPServer.ConnectionHandlergetConnectionHandler()Returns the handler to use for processing connectionsStringgetHost()Returns the specific ip address/host to bind tointgetIdleTimeTimeout()Gets the idle time, in seconds, for the worker thread pool.intgetMaxWorkers()Returns the max worker threads to allow.intgetMinWorkers()Returns the min worker threads to allow.StringgetName()Gets the name used for worker threads.intgetPort()Returns the port to bind to.Thread.StategetStatus()booleanisListenerDaemon()Indicates whether the listener thread is a daemon thread.booleanisWorkerDaemon()Indicates whether worker threads are daemon threads.voidsetHost(String host)Sets the specific ip address/host to bind tovoidsetIdleTimeTimeout(int idleTimeTimeout)Sets the idle time, in seconds, for the worker thread pool.voidsetListenerDaemon(boolean daemon)Sets whether the listener thread is marked as a daemon thread.voidsetMaxWorkers(int maxWorkers)Sets the max worker thread to allow.voidsetMinWorkers(int minWorkers)Sets the min worker thread to allow.voidsetName(String name)Sets the base name used for worker threads.voidsetPort(int port)Sets the port to bind to.voidsetWorkerDaemon(boolean daemon)Sets whether worker threads are marked as daemon threads.InetSocketAddressstart()Starts the server.voidstartShutdown()Initiates shutdown by closing the listening socket. 
 - 
 
- 
- 
Constructor Detail
- 
GenericTCPServer
public GenericTCPServer(GenericTCPServer.ConnectionHandler handler)
Creates a new server- Parameters:
 handler- the handler to handle requests
 
 - 
 
- 
Method Detail
- 
getConnectionHandler
public GenericTCPServer.ConnectionHandler getConnectionHandler()
Returns the handler to use for processing connections- Returns:
 - the configured connection handler
 
 
- 
getMaxWorkers
public int getMaxWorkers()
Returns the max worker threads to allow.- Returns:
 - The max worker threads to allow.
 
 
- 
setMaxWorkers
public void setMaxWorkers(int maxWorkers)
Sets the max worker thread to allow.- Parameters:
 maxWorkers- The max worker threads to allow.
 
- 
getMinWorkers
public int getMinWorkers()
Returns the min worker threads to allow.- Returns:
 - The min worker threads to allow.
 
 
- 
setMinWorkers
public void setMinWorkers(int minWorkers)
Sets the min worker thread to allow.- Parameters:
 minWorkers- The min worker threads to allow.
 
- 
getHost
public String getHost()
Returns the specific ip address/host to bind to- Returns:
 - the specific ip address/host to bind to
 
 
- 
setHost
public void setHost(String host)
Sets the specific ip address/host to bind to- Parameters:
 ipaddress- the specific ip/host address to bind to
 
- 
start
public final InetSocketAddress start()
Starts the server.- Returns:
 - the listening address of the server
 - Throws:
 DRException- if errors occur during start up
 
- 
startShutdown
public final void startShutdown()
Initiates shutdown by closing the listening socket. Pending requests will be allowed to finish. 
- 
awaitShutdown
public final void awaitShutdown(long timeout, TimeUnit unit) throws InterruptedExceptionWaits for pending requests to finish. Upon successful completion of this method, the server is in a logically shutdown state such that it can be restarted.- Parameters:
 timeout- the length of the timeoutunit- the unit of the timeout- Throws:
 InterruptedException- if interrupted while waiting for shutdown
 
- 
getPort
public int getPort()
Returns the port to bind to. The default value of zero means chose an ephemeral port.- Returns:
 - the configured port
 
 
- 
setPort
public void setPort(int port)
Sets the port to bind to. The default value of zero means chose an ephemeral port.- Parameters:
 port- the port to which to bind
 
- 
isListenerDaemon
public boolean isListenerDaemon()
Indicates whether the listener thread is a daemon thread.- Returns:
 trueif the listener is a daemon thread,falseotherwise.
 
- 
setListenerDaemon
public void setListenerDaemon(boolean daemon)
Sets whether the listener thread is marked as a daemon thread.- Parameters:
 daemon- indicates whether the listener is a daemon or not- See Also:
 Thread.setDaemon(boolean)
 
- 
isWorkerDaemon
public boolean isWorkerDaemon()
Indicates whether worker threads are daemon threads.- Returns:
 trueif workers are daemon threads,falseotherwise.
 
- 
setWorkerDaemon
public void setWorkerDaemon(boolean daemon)
Sets whether worker threads are marked as daemon threads.- Parameters:
 daemon- indicates whether workers are daemons or not- See Also:
 Thread.setDaemon(boolean)
 
- 
getStatus
public final Thread.State getStatus()
 
- 
setName
public void setName(String name)
Sets the base name used for worker threads.- Parameters:
 name- the base name to use
 
- 
getName
public String getName()
Gets the name used for worker threads.- Returns:
 - the base name of worker threads
 
 
- 
setIdleTimeTimeout
public void setIdleTimeTimeout(int idleTimeTimeout)
Sets the idle time, in seconds, for the worker thread pool. Worker threads will be removed from the pool after being idle for this amount of time.- Parameters:
 idleTimeTimeout- the number of seconds a thread may be idle
 
- 
getIdleTimeTimeout
public int getIdleTimeTimeout()
Gets the idle time, in seconds, for the worker thread pool.- Returns:
 - the number seconds a thread may be idle
 
 
- 
disableThreadPooling
public void disableThreadPooling()
Disables thread pooling of workers. Every new request starts a new thread which terminates after handling the request. 
 - 
 
 -