Package net.officefloor.server
Class SocketManager
- java.lang.Object
-
- net.officefloor.server.SocketManager
-
public class SocketManager extends java.lang.Object
Manages theSocket
interaction.- Author:
- Daniel Sagenschneider
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
DefaultServerSocket
backlog size.
-
Constructor Summary
Constructors Constructor Description SocketManager(int listenerCount, int socketReceiveBufferSize, int maxReadsOnSelect, int maxActiveSocketRequests, StreamBufferPool<java.nio.ByteBuffer> bufferPool, int socketSendBufferSize)
Instantiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> java.net.ServerSocket
bindServerSocket(int port, ServerSocketDecorator serverSocketDecorator, AcceptedSocketDecorator acceptedSocketDecorator, SocketServicerFactory<R> socketServicerFactory, RequestServicerFactory<R> requestServicerFactory)
Binds aServerSocket
to be serviced.static long
getMaxDirectMemory()
Obtains the max direct memory.static long
getMaxHeapMemory()
Obtains the max heap memory.java.lang.Runnable[]
getRunnables()
Obtains theRunnable
instances to be executed for thisSocketManager
.void
shutdown()
Shuts down thisSocketManager
.
-
-
-
Field Detail
-
DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
public static final int DEFAULT_SERVER_SOCKET_BACKLOG_SIZE
DefaultServerSocket
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 ofSocketManager.SocketListener
instances.socketReceiveBufferSize
- Receive buffer size for theSocket
.maxReadsOnSelect
- Maximum number of reads perSocketChannel
per select. TheSelector
has locking overheads that slow performance. By undertaking multiple reads on theSocketChannel
it makes draining and servicing more efficient (and subsequently faster). This also allows theStreamBuffer
sizes to be smaller than the receiveSocket
buffer size (but still maintain efficiency).maxActiveSocketRequests
- Maximum number of activeSocketManager.SocketRequest
instances per acceptedSocket
.bufferPool
-StreamBufferPool
.socketSendBufferSize
- Send buffer size for theSocket
.- Throws:
java.io.IOException
- If fails to initialiseSocket
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 theRunnable
instances to be executed for thisSocketManager
.- Returns:
Runnable
instances to be executed for thisSocketManager
.
-
bindServerSocket
public final <R> java.net.ServerSocket bindServerSocket(int port, ServerSocketDecorator serverSocketDecorator, AcceptedSocketDecorator acceptedSocketDecorator, SocketServicerFactory<R> socketServicerFactory, RequestServicerFactory<R> requestServicerFactory) throws java.io.IOException
Binds aServerSocket
to be serviced.- Type Parameters:
R
- Request type.- Parameters:
port
- Port for theServerSocket
.serverSocketDecorator
- OptionalServerSocketDecorator
. May benull
.acceptedSocketDecorator
- OptionalAcceptedSocketDecorator
. May benull
.socketServicerFactory
-SocketServicerFactory
to service accepted connections.requestServicerFactory
-RequestServicerFactory
to service requests on theSocket
.- Returns:
- Bound
ServerSocket
. - Throws:
java.io.IOException
- If fails to bind theServerSocket
.
-
shutdown
public final void shutdown() throws java.io.IOException
Shuts down thisSocketManager
. This involves closing allSocket
instances being managed and stopping theSocketManager.SocketListener
instances.- Throws:
java.io.IOException
- If fails to shutdown thisSocketManager
.
-
-