Package com.iizix
Class Worker
java.lang.Object
com.iizix.nio.WorkerNIO
com.iizix.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- Fields inherited from class com.iizix.nio.WorkerNIO- LAN_BUFFER_SIZE
- Constructor SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- boolean- dispose()Disposes of the worker.Get the SessionInfo from the Worker.- booleanGets the verbose flag.- booleanChecks if the calling thread is the worker thread or not.- boolean- post- (WorkerTask<?, - ?, - ?> task) Posts a task for execution at a later stage.- booleanHelper method to post a runnable for execution.- boolean- postAndWait- (WorkerTask<?, - ?, - ?> task) Posts a task for execution at a later stage and waits for it's completion.- boolean- postModalWait- (WorkerTask<?, - ?, - ?> task) Posts a task for execution at a later stage and waits for it's completion when a call to- relaseModal(modalID,result)is called.- 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.- boolean- releaseModal- (int modalID, Object result) Releases a modal waiting task and sets its result.- boolean- runNowOrPost- (Runnable runnable) Helper method to perform the execution of the runnable now IF the current thread is the worker thread, otherwise a post is done.- void- setVerbose- (boolean isVerbose) Sets the verbose flag, also used for new clients.- Methods inherited from class com.iizix.nio.WorkerNIO- checkDisposed, isDisposed, register, registerTimeoutHandler, unregisterTimeoutHandler, wakeupSelector
- Constructor Details- WorkerCreates an instance of the Worker queue.- Parameters:
- sessionInfo- The SessionInfo for an EndPoint, null for server or (single) main worker (for Eclipse case).
- Throws:
- IOException- If an I/O error occurs.
 
 
- Method Details- isVerbosepublic boolean isVerbose()Gets the verbose flag.- Returns:
- The verbose output flag on console.
 
- setVerbosepublic void setVerbose- (boolean isVerbose) Sets the verbose flag, also used for new clients.- Parameters:
- isVerbose- The verbose output flag on console.
 
- getSessionInfoGet the SessionInfo from the Worker.- Returns:
- The SessionInfo for an EndPoint, null for server or (single) main worker (for Eclipse case).
 
- processSelectorKeysProcess selector keys.- Overrides:
- processSelectorKeysin class- WorkerNIO
- Parameters:
- now- Checking of selectors now or when queue is empty.
- 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.
- isWorkerThreadpublic boolean isWorkerThread()Checks if the calling thread is the worker thread or not.- Returns:
- true, same calling thread as the worker thread, false otherwise.
 
- processOnceprotected boolean processOnce()Processes once a single write-read-execute operation. This is called from the process-loop and postModalWait.- Overrides:
- processOncein class- WorkerNIO
- Returns:
- true for success, false for cancelled or error.
 
- 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).
- postHelper method to post a runnable for execution.- Parameters:
- runnable- The runnable.
- Returns:
- true if the task has been queue successfully, false if the worker has been disposed of, or task couldn't be queue, because e.g. no processing thread is assigned to the worker.
 
- postPosts a task for execution at a later stage.- Parameters:
- task- The task to post, non-null.
- Returns:
- true if the task has been queue successfully, false if the worker has been disposed of, or task couldn't be queue, because e.g. no processing thread is assigned to the worker.
- Throws:
- IllegalStateException- If the task already has been posted to a worker.
 
- postAndWaitPosts a task for execution at a later stage and waits for it's completion. If this method is called from the worker thread (that is not allowed to post-and-wait), the task is just executed directly as if it was called with the- executemethod.- Parameters:
- task- The task to post, non-null.
- Returns:
- true if the task has been queue successfully, false if the worker has been disposed of, or task couldn't be queued.
- Throws:
- InterruptedException- If the task was interrupted.
- IllegalStateException- If the task already has been posted to a worker.
 
- runNowOrPostHelper method to perform the execution of the runnable now IF the current thread is the worker thread, otherwise a post is done.- Parameters:
- runnable- The runnable.
- Returns:
- true If the task has been executed, false if queued.
- Throws:
- IllegalStateException- If the worker is disposed of.
 
- postModalWaitPosts a task for execution at a later stage and waits for it's completion when a call to- relaseModal(modalID,result)is called.- Parameters:
- task- The task to post, non-null.
- Returns:
- true if the task has been queue successfully and completed (including the modal release), false if the worker has been disposed of, or task couldn't be queued.
- Throws:
- InterruptedException- If the task was interrupted.
- IllegalStateException- If the task already has been posted to a worker.
 
- releaseModalReleases a modal waiting task and sets its result.- Parameters:
- modalID- The modal ID of the task.
- result- The result to set for the task.
- Returns:
- true for success, false for failure.
- Throws:
- IllegalStateException- If the task is already released.