Class SocketManager


  • public class SocketManager
    extends java.lang.Object
    Manages the Socket interaction.
    Author:
    Daniel Sagenschneider
    • Field Detail

      • DEFAULT_SERVER_SOCKET_BACKLOG_SIZE

        public static final int DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
        Default ServerSocket backlog size.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SocketManager

        public SocketManager​(int listenerCount,
                             int socketReceiveBufferSize,
                             int maxReadsOnSelect,
                             int maxActiveSocketRequests,
                             StreamBufferPool<java.nio.ByteBuffer> bufferPool,
                             int socketSendBufferSize)
                      throws java.io.IOException
        Instantiate.
        Parameters:
        listenerCount - Number of SocketManager.SocketListener instances.
        socketReceiveBufferSize - Receive buffer size for the Socket.
        maxReadsOnSelect - Maximum number of reads per SocketChannel per select. The Selector has locking overheads that slow performance. By undertaking multiple reads on the SocketChannel it makes draining and servicing more efficient (and subsequently faster). This also allows the StreamBuffer sizes to be smaller than the receive Socket buffer size (but still maintain efficiency).
        maxActiveSocketRequests - Maximum number of active SocketManager.SocketRequest instances per accepted Socket.
        bufferPool - StreamBufferPool.
        socketSendBufferSize - Send buffer size for the Socket.
        Throws:
        java.io.IOException - If fails to initialise Socket management.
    • Method Detail

      • getMaxDirectMemory

        public static long getMaxDirectMemory()
        Obtains the max direct memory.
        Returns:
        Max direct memory.
      • getMaxHeapMemory

        public static long getMaxHeapMemory()
        Obtains the max heap memory.
        Returns:
        Max heap memory.
      • getRunnables

        public final java.lang.Runnable[] getRunnables()
        Obtains the Runnable instances to be executed for this SocketManager.
        Returns:
        Runnable instances to be executed for this SocketManager.
      • shutdown

        public final void shutdown()
                            throws java.io.IOException
        Shuts down this SocketManager. This involves closing all Socket instances being managed and stopping the SocketManager.SocketListener instances.
        Throws:
        java.io.IOException - If fails to shutdown this SocketManager.