Class ServerSocketComm

  • All Implemented Interfaces:
    ISocketComm, IWorkerTimeout

    public class ServerSocketComm
    extends java.lang.Object
    implements ISocketComm
    The ServerSocketComm class is used to open a plain server socket with an optional bind address. All responses is sent to the ServerSocketCommListener.
    Author:
    Christopher Mindus
    • Nested Class Summary

      Nested Classes 
      Modifier and TypeClassDescription
      static class ServerSocketComm.State
      The state of the communication link.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidcheckTimeout​(long timeNow)
      Performs a timeout check for the socket channel.
      booleanclose()
      Call this method to close the socket.
      booleanclose​(boolean rightNow)
      Call this method to close the socket.
      longgetRemainingTimeout​(long timeNow)
      Gets the socket timeout value remaining.
      ServerSocketComm.StategetState()
      Gets the state of the connection.
      booleanisClosed()
      Checks if the connection is disposed of.
      voidopen()
      Opens the communication.
      voidprocess​(java.nio.ByteBuffer buffer)
      Processes the SelectionKey as it has generated an event.
      • Methods inherited from class java.lang.Object

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

      • ServerSocketComm

        public ServerSocketComm​(ServerSocketCommProps properties,
                                Worker worker,
                                ServerSocketCommListener listener)
        Creates a new Server Socket Communication channel as UNINITIALIZED.
        Parameters:
        properties - The server socket properties.
        worker - The worker thread for socket processing.
        listener - The listener for server socket events.
    • Method Detail

      • open

        public void open()
                  throws java.io.IOException
        Opens the communication.
        Throws:
        java.io.IOException
      • process

        public void process​(java.nio.ByteBuffer buffer)
        Processes the SelectionKey as it has generated an event.
        Specified by:
        process in interface ISocketComm
        Parameters:
        buffer - The direct buffer allocated by the worker.
      • isClosed

        public boolean isClosed()
        Checks if the connection is disposed of.
      • close

        public boolean close()
        Call this method to close the socket. Same as close(true/false).
        Returns:
        true if closed, false if already closed.
      • close

        public boolean close​(boolean rightNow)
        Call this method to close the socket.
        Specified by:
        close in interface ISocketComm
        Parameters:
        rightNow - In thins implementation this flag has no effect.
        Returns:
        true if closed, false if already closed.
      • getRemainingTimeout

        public long getRemainingTimeout​(long timeNow)
        Gets the socket timeout value remaining.

        The Server Socket Communication always returns -1 for indefinite timeout.

        Specified by:
        getRemainingTimeout in interface IWorkerTimeout
        Parameters:
        timeNow - The current time.
        Returns:
        Time in milliseconds until timeout, NOTE! -1 for indefinite timeout.
      • checkTimeout

        public void checkTimeout​(long timeNow)
        Performs a timeout check for the socket channel. This is called to all channels, so each channel must check its own state.

        The Server Socket Communication performs nothing for this method.

        Specified by:
        checkTimeout in interface IWorkerTimeout
        Parameters:
        timeNow - The current time.