Package net.officefloor.server
Class SocketManager
java.lang.Object
net.officefloor.server.SocketManager
Manages the
Socket interaction.- Author:
- Daniel Sagenschneider
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSocketManager(int listenerCount, int socketReceiveBufferSize, int maxReadsOnSelect, int maxActiveSocketRequests, StreamBufferPool<ByteBuffer> bufferPool, int socketSendBufferSize) Instantiate. -
Method Summary
Modifier and TypeMethodDescriptionfinal <R> ServerSocketbindServerSocket(int port, ServerSocketDecorator serverSocketDecorator, AcceptedSocketDecorator acceptedSocketDecorator, SocketServicerFactory<R> socketServicerFactory, RequestServicerFactory<R> requestServicerFactory) Binds aServerSocketto be serviced.static longObtains the max direct memory.static longObtains the max heap memory.final Runnable[]Obtains theRunnableinstances to be executed for thisSocketManager.final voidshutdown()Shuts down thisSocketManager.
-
Field Details
-
DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
public static final int DEFAULT_SERVER_SOCKET_BACKLOG_SIZEDefaultServerSocketbacklog size.- See Also:
-
-
Constructor Details
-
SocketManager
public SocketManager(int listenerCount, int socketReceiveBufferSize, int maxReadsOnSelect, int maxActiveSocketRequests, StreamBufferPool<ByteBuffer> bufferPool, int socketSendBufferSize) throws IOException Instantiate.- Parameters:
listenerCount- Number ofSocketManager.SocketListenerinstances.socketReceiveBufferSize- Receive buffer size for theSocket.maxReadsOnSelect- Maximum number of reads perSocketChannelper select. TheSelectorhas locking overheads that slow performance. By undertaking multiple reads on theSocketChannelit makes draining and servicing more efficient (and subsequently faster). This also allows theStreamBuffersizes to be smaller than the receiveSocketbuffer size (but still maintain efficiency).maxActiveSocketRequests- Maximum number of activeSocketManager.SocketRequestinstances per acceptedSocket.bufferPool-StreamBufferPool.socketSendBufferSize- Send buffer size for theSocket.- Throws:
IOException- If fails to initialiseSocketmanagement.
-
-
Method Details
-
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
Obtains theRunnableinstances to be executed for thisSocketManager.- Returns:
Runnableinstances to be executed for thisSocketManager.
-
bindServerSocket
public final <R> ServerSocket bindServerSocket(int port, ServerSocketDecorator serverSocketDecorator, AcceptedSocketDecorator acceptedSocketDecorator, SocketServicerFactory<R> socketServicerFactory, RequestServicerFactory<R> requestServicerFactory) throws IOException Binds aServerSocketto be serviced.- Type Parameters:
R- Request type.- Parameters:
port- Port for theServerSocket.serverSocketDecorator- OptionalServerSocketDecorator. May benull.acceptedSocketDecorator- OptionalAcceptedSocketDecorator. May benull.socketServicerFactory-SocketServicerFactoryto service accepted connections.requestServicerFactory-RequestServicerFactoryto service requests on theSocket.- Returns:
- Bound
ServerSocket. - Throws:
IOException- If fails to bind theServerSocket.
-
shutdown
Shuts down thisSocketManager. This involves closing allSocketinstances being managed and stopping theSocketManager.SocketListenerinstances.- Throws:
IOException- If fails to shutdown thisSocketManager.
-