Package gov.usgs.util

Class SocketAcceptor

  • All Implemented Interfaces:
    java.lang.Runnable

    public class SocketAcceptor
    extends java.lang.Object
    implements java.lang.Runnable
    Accept socket connections from a ServerSocket, and notify a listener using a separate thread.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void run()
      Accept connections until the shutdown method is called.
      void start()
      Start accepting connections in a background thread.
      void stop()
      Stop accepting connections.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SocketAcceptor

        public SocketAcceptor​(java.net.ServerSocket listener,
                              SocketListenerInterface callback)
        Create a new SocketAcceptor object that uses a single thread executor.
        Parameters:
        listener - the server socket to accept connections from.
        callback - the object that processes accepted connections.
      • SocketAcceptor

        public SocketAcceptor​(java.net.ServerSocket listener,
                              SocketListenerInterface callback,
                              java.util.concurrent.ExecutorService executor)
        Parameters:
        listener - the server socket to accept connections from.
        callback - the object that processes accepted connections.
        executor - the executor used to invoke callback.
    • Method Detail

      • start

        public void start()
        Start accepting connections in a background thread.
      • stop

        public void stop()
        Stop accepting connections.
      • run

        public void run()
        Accept connections until the shutdown method is called.
        Specified by:
        run in interface java.lang.Runnable