Class GenericTCPServer

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.
  • Constructor Details

  • Method Details

    • 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 InterruptedException
      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 timeout
      unit - 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:
      true if the listener is a daemon thread, false otherwise.
    • 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:
      true if workers are daemon threads, false otherwise.
    • 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

      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.