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 SummaryFieldsModifier and TypeFieldDescription- static final intThe multi-purpose buffer allocated by the worker (24KB or 16+8KB, 0x6000).
- Constructor SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- voidChecks if the worker is disposed.- boolean- dispose()Disposes of the worker.- booleanChecks if the worker is disposed of.- void- process()Starts processing the worker queue operations.- protected booleanProcesses once a single write-read-execute operation.- protected boolean- processSelectorKeys- (boolean now) Process selector keys.- register- (ISocketComm comm, SelectableChannel channel, int ops) Registers a SocketComm - opened - instance with the IO Selector associated with the Worker.- boolean- registerTimeoutHandler- (IWorkerTimeout handler) Registers a new timeout handler.- boolean- unregisterTimeoutHandler- (IWorkerTimeout handler) Unregisters a timeout handler.- protected voidWake-up selector.
- Field Details- LAN_BUFFER_SIZEpublic 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- WorkerNIOCreates an instance of the Worker queue.- Throws:
- IOException- If an I/O error occurs.
 
 
- Method Details- registerTimeoutHandlerRegisters 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.
 
- unregisterTimeoutHandlerUnregisters a timeout handler.- Parameters:
- handler- The timeout handler.
- Returns:
- true for success, false if not registered.
 
- registerpublic SelectionKey register- (ISocketComm comm, SelectableChannel channel, int ops) throws ClosedChannelException Registers a SocketComm - opened - instance with the IO 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:
- ClosedChannelException- If the worker is disposed of or the IO Selector is closed.
 
- processSelectorKeysProcess 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.
 
- processpublic void process()Starts processing the worker queue operations.
- processOnceprotected 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.
 
- checkDisposedpublic 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.
 
- disposepublic boolean dispose()Disposes of the worker. All pending queued events are discarded along with all possible IO operations. Any callback functions waiting for task to complete will be informed (cancelled task).- Returns:
- true if disposed of, false if already disposed.
 
- isDisposedpublic boolean isDisposed()Checks if the worker is disposed of.- Returns:
- true if worker is disposed, false otherwise.
 
- wakeupSelectorprotected void wakeupSelector()Wake-up selector. Only called by subclasses.