Package com.iizix.comm
Class ServerSocketComm
java.lang.Object
com.iizix.comm.ServerSocketComm
- All Implemented Interfaces:
ISocketComm
,IWorkerTimeout
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
Modifier and TypeClassDescriptionstatic enum
The state of the communication link.Field Summary
Constructor Summary
ConstructorDescriptionServerSocketComm
(ServerSocketCommProps properties, Worker worker, ServerSocketCommListener listener) Creates a new Server Socket Communication channel as UNINITIALIZED.Method Summary
Modifier and TypeMethodDescriptionvoid
checkTimeout
(long timeNow) Performs a timeout check for the socket channel.boolean
close()
Call this method to close the socket.boolean
close
(boolean rightNow) Call this method to close the socket.long
getRemainingTimeout
(long timeNow) Gets the socket timeout value remaining.getState()
Gets the state of the connection.boolean
isClosed()
Checks if the connection is disposed of.void
open()
Opens the communication.void
process
(ByteBuffer buffer) Processes the SelectionKey as it has generated an event.
Field Details
properties
The properties for the socket.
Constructor Details
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 Details
open
Opens the communication.- Throws:
IOException
process
Processes the SelectionKey as it has generated an event.- Specified by:
process
in interfaceISocketComm
- Parameters:
buffer
- The direct buffer allocated by the worker.
getState
Gets the state of the connection.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 interfaceISocketComm
- 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 interfaceIWorkerTimeout
- 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 interfaceIWorkerTimeout
- Parameters:
timeNow
- The current time.