Package net.officefloor.server
Class SocketManager
- java.lang.Object
-
- net.officefloor.server.SocketManager
-
public class SocketManager extends java.lang.ObjectManages theSocketinteraction.- Author:
- Daniel Sagenschneider
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SERVER_SOCKET_BACKLOG_SIZEDefaultServerSocketbacklog size.
-
Constructor Summary
Constructors Constructor Description SocketManager(int listenerCount, int socketReceiveBufferSize, int maxReadsOnSelect, StreamBufferPool<java.nio.ByteBuffer> bufferPool, int socketSendBufferSize)Instantiate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> voidbindServerSocket(int port, ServerSocketDecorator serverSocketDecorator, AcceptedSocketDecorator acceptedSocketDecorator, SocketServicerFactory<R> socketServicerFactory, RequestServicerFactory<R> requestServicerFactory)Binds aServerSocketto be serviced.java.lang.Runnable[]getRunnables()Obtains theRunnableinstances to be executed for thisSocketManager.StreamBufferPool<java.nio.ByteBuffer>getStreamBufferPool()Obtains theStreamBufferPoolused by thisSocketManager.voidshutdown()Shuts down thisSocketManager.
-
-
-
Field Detail
-
DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
public static final int DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
DefaultServerSocketbacklog size.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SocketManager
public SocketManager(int listenerCount, int socketReceiveBufferSize, int maxReadsOnSelect, StreamBufferPool<java.nio.ByteBuffer> bufferPool, int socketSendBufferSize) throws java.io.IOExceptionInstantiate.- 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).bufferPool-StreamBufferPool.socketSendBufferSize- Send buffer size for theSocket.- Throws:
java.io.IOException- If fails to initialiseSocketmanagement.
-
-
Method Detail
-
getStreamBufferPool
public final StreamBufferPool<java.nio.ByteBuffer> getStreamBufferPool()
Obtains theStreamBufferPoolused by thisSocketManager.- Returns:
StreamBufferPoolused by thisSocketManager.
-
getRunnables
public final java.lang.Runnable[] getRunnables()
Obtains theRunnableinstances to be executed for thisSocketManager.- Returns:
Runnableinstances to be executed for thisSocketManager.
-
bindServerSocket
public final <R> void bindServerSocket(int port, ServerSocketDecorator serverSocketDecorator, AcceptedSocketDecorator acceptedSocketDecorator, SocketServicerFactory<R> socketServicerFactory, RequestServicerFactory<R> requestServicerFactory) throws java.io.IOExceptionBinds 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.- Throws:
java.io.IOException- If fails to bind theServerSocket.
-
shutdown
public final void shutdown() throws java.io.IOExceptionShuts down thisSocketManager. This involves closing allSocketinstances being managed and stopping theSocketManager.SocketListenerinstances.- Throws:
java.io.IOException- If fails to shutdown thisSocketManager.
-
-