Package com.iizix.comm
Class ServerSocketComm
- java.lang.Object
- com.iizix.comm.ServerSocketComm
- All Implemented Interfaces:
ISocketComm
,IWorkerTimeout
public class ServerSocketComm extends java.lang.Object implements ISocketComm
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
Nested Classes Modifier and Type Class Description static class
ServerSocketComm.State
The state of the communication link.
Field Summary
Fields Modifier and Type Field Description ServerSocketCommProps
properties
The properties for the socket.
Constructor Summary
Constructors Constructor Description ServerSocketComm(ServerSocketCommProps properties, Worker worker, ServerSocketCommListener listener)
Creates a new Server Socket Communication channel as UNINITIALIZED.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.ServerSocketComm.State
getState()
Gets the state of the connection.boolean
isClosed()
Checks if the connection is disposed of.void
open()
Opens the communication.void
process(java.nio.ByteBuffer buffer)
Processes the SelectionKey as it has generated an event.
Field Detail
properties
public final ServerSocketCommProps properties
The properties for the socket.
Constructor Detail
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 Detail
open
public void open() throws java.io.IOException
Opens the communication.- Throws:
java.io.IOException
process
public void process(java.nio.ByteBuffer buffer)
Processes the SelectionKey as it has generated an event.- Specified by:
process
in interfaceISocketComm
- Parameters:
buffer
- The direct buffer allocated by the worker.
getState
public ServerSocketComm.State 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.