java.lang.Object
com.pervasive.datarush.commons.util.GenericTCPServer
General purpose TCP server that provides thread pooling, start and stop code.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandles incomming connectionsfinal classInformation passed to a server implementation to provide execution context. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new server -
Method Summary
Modifier and TypeMethodDescriptionfinal voidawaitShutdown(long timeout, TimeUnit unit) Waits for pending requests to finish.voidDisables thread pooling of workers.Returns the handler to use for processing connectionsgetHost()Returns the specific ip address/host to bind tointGets the idle time, in seconds, for the worker thread pool.intReturns the max worker threads to allow.intReturns the min worker threads to allow.getName()Gets the name used for worker threads.intgetPort()Returns the port to bind to.final Thread.StatebooleanIndicates whether the listener thread is a daemon thread.booleanIndicates whether worker threads are daemon threads.voidSets 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.voidSets 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.final InetSocketAddressstart()Starts the server.final voidInitiates shutdown by closing the listening socket.
-
Constructor Details
-
GenericTCPServer
Creates a new server- Parameters:
handler- the handler to handle requests
-
-
Method Details
-
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
Returns the specific ip address/host to bind to- Returns:
- the specific ip address/host to bind to
-
setHost
Sets the specific ip address/host to bind to- Parameters:
ipaddress- the specific ip/host address to bind to
-
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
Waits 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:
-
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:
-
getStatus
-
setName
Sets the base name used for worker threads.- Parameters:
name- the base name to use
-
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.
-