Package com.iizix.nio
Class WorkerNIO
java.lang.Object
com.iizix.nio.WorkerNIO
- Direct Known Subclasses:
Worker
The Worker is a class that handles all communication with "plain" sockets, received and sent (pending) messages to connectors, along with handling the session queue.
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe multi-purpose buffer allocated by the worker (24KB or 16+8KB, 0x6000).Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidChecks if the worker is disposed.booleandispose()Disposes of the worker.booleanChecks if the worker is disposed of.voidprocess()Starts processing the worker queue operations.protected booleanProcesses once a single write-read-execute operation.protected booleanprocessSelectorKeys(boolean now) Process selector keys.register(ISocketComm comm, SelectableChannel channel, int ops) Registers a SocketComm - opened - instance with the I/O Selector associated with the Worker.booleanregisterTimeoutHandler(IWorkerTimeout handler) Registers a new timeout handler.booleanunregisterTimeoutHandler(IWorkerTimeout handler) Unregisters a timeout handler.protected voidWake-up selector.
Field Details
LAN_BUFFER_SIZE
public static final int LAN_BUFFER_SIZEThe multi-purpose buffer allocated by the worker (24KB or 16+8KB, 0x6000). The size is chosen to maximize localhost communication and large buffer transmits over 1Gb LAN's.- See Also:
Constructor Details
WorkerNIO
Creates an instance of the Worker queue.- Throws:
IOException- If an I/O error occurs.
Method Details
registerTimeoutHandler
Registers a new timeout handler. Calling this method more than once for the same handler does not change anything.- Parameters:
handler- The timeout handler.- Returns:
- true for success, false if already registered.
unregisterTimeoutHandler
Unregisters a timeout handler.- Parameters:
handler- The timeout handler.- Returns:
- true for success, false if not registered.
register
public SelectionKey register(ISocketComm comm, SelectableChannel channel, int ops) throws IOException Registers a SocketComm - opened - instance with the I/O Selector associated with the Worker.- Parameters:
comm- The communication instance to attach to the selector.channel- The selectable channel (socket or server-socket channels).ops- The Operations the communication instance wishes to listen to.- Returns:
- The selection key for the socket channel.
- Throws:
IOException- For I/O operationss.
processSelectorKeys
Process selector keys.- Parameters:
now- Flag to process now or at a later stage.- Returns:
- true if something was found to process, false for nothing.
- Throws:
IOException- For I/O exceptions.
process
public void process()Starts processing the worker queue operations.processOnce
protected boolean processOnce()Processes once a single write-read-execute operation. This is called from the process-loop and postModalWait.- Returns:
- true for success, false for cancelled or error.
checkDisposed
public void checkDisposed()Checks if the worker is disposed. This method does nothing if the worker is not disposed of.- Throws:
IllegalStateException- If the worker is disposed of.
dispose
public boolean dispose()Disposes of the worker. All pending queued events are discarded along with all possible I/O operations. Any callback functions waiting for task to complete will be informed (cancelled task).- Returns:
- true if disposed of, false if already disposed.
isDisposed
public boolean isDisposed()Checks if the worker is disposed of.- Returns:
- true if worker is disposed, false otherwise.
wakeupSelector
protected void wakeupSelector()Wake-up selector. Only called by subclasses.