Class SocketListener

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    class SocketListener
    extends java.lang.Object
    implements java.io.Closeable
    The SocketListener object is represents the interface to the server that the clients can connect to. This is responsible for making call backs to the SocketAcceptor when there is a new connection waiting to be accepted. When the connection is to be closed the interface object can be closed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private SocketAcceptor acceptor
      This is the acceptor that is used to accept the connections.
      private Reactor reactor
      This is the reactor used to notify the acceptor of sockets.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      This is used to close the connection and the server socket used to accept connections.
      java.net.SocketAddress getAddress()
      This is used to acquire the local socket address that this is listening to.
      void process()
      This is used to register the socket acceptor to listen for new connections that are ready to be accepted.
      • Methods inherited from class java.lang.Object

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

      • acceptor

        private final SocketAcceptor acceptor
        This is the acceptor that is used to accept the connections.
      • reactor

        private final Reactor reactor
        This is the reactor used to notify the acceptor of sockets.
    • Constructor Detail

      • SocketListener

        public SocketListener​(java.net.SocketAddress address,
                              SocketProcessor processor,
                              TraceAnalyzer analyzer)
                       throws java.io.IOException
        Constructor for the SocketListener object. This needs a socket address and a processor to hand created sockets to. This creates a Reactor which will notify the acceptor when there is a new connection waiting to be accepted.
        Parameters:
        address - this is the address to listen for new sockets
        processor - this is the processor that sockets are handed to
        analyzer - this is used to create a trace to monitor events
        Throws:
        java.io.IOException
      • SocketListener

        public SocketListener​(java.net.SocketAddress address,
                              SocketProcessor processor,
                              TraceAnalyzer analyzer,
                              javax.net.ssl.SSLContext context)
                       throws java.io.IOException
        Constructor for the SocketListener object. This needs a socket address and a processor to hand created sockets to. This creates a Reactor which will notify the acceptor when there is a new connection waiting to be accepted.
        Parameters:
        address - this is the address to listen for new sockets
        processor - this is the processor that sockets are handed to
        analyzer - this is used to create a trace to monitor events
        context - this is the SSL context used for secure HTTPS
        Throws:
        java.io.IOException
    • Method Detail

      • getAddress

        public java.net.SocketAddress getAddress()
        This is used to acquire the local socket address that this is listening to. This required in case the socket address that is specified is an emphemeral address, that is an address that is assigned dynamically when a port of 0 is specified.
        Returns:
        this returns the address for the listening address
      • process

        public void process()
                     throws java.io.IOException
        This is used to register the socket acceptor to listen for new connections that are ready to be accepted. Once this is registered it will remain registered until the interface is closed, at which point the socket is closed.
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        This is used to close the connection and the server socket used to accept connections. This will perform a close of the connected server socket and the dispatching thread.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException