public final class NioDispatchSource extends AbstractDispatchObject implements DispatchSource
Implements the DispatchSource interface.
Description: An NioDispatchSource is associated with one SelectableChannel but supports being registered on selectors associated with different thread. Usually just one at time tho.
| Modifier and Type | Class and Description |
|---|---|
static class |
NioDispatchSource.KeyState |
| Modifier and Type | Field and Description |
|---|---|
(package private) java.util.concurrent.atomic.AtomicBoolean |
canceled |
(package private) Task |
cancelHandler |
(package private) java.nio.channels.SelectableChannel |
channel |
static boolean |
DEBUG |
(package private) Task |
eventHandler |
(package private) int |
interestOps |
(package private) java.lang.ThreadLocal<NioDispatchSource.KeyState> |
keyState |
(package private) DispatchQueue |
selectorQueue |
private Task |
updateInterestTask |
targetQueuestartup, suspended| Constructor and Description |
|---|
NioDispatchSource(HawtDispatcher dispatcher,
java.nio.channels.SelectableChannel channel,
int interestOps,
DispatchQueue targetQueue) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Asynchronously cancel the dispatch source, preventing any further invocation
of its event handler runnable.
|
protected void |
debug(java.lang.String str,
java.lang.Object... args) |
protected void |
debug(java.lang.Throwable thrown,
java.lang.String str,
java.lang.Object... args) |
void |
fire(int readyOps) |
private NioManager |
getCurrentNioManager() |
java.lang.Void |
getData() |
(package private) void |
internal_cancel() |
boolean |
isCanceled() |
private boolean |
isCurrent(DispatchQueue q) |
private void |
key_cancel() |
protected void |
onResume() |
protected void |
onStartup() |
protected void |
onSuspend() |
private static java.lang.String |
opsToString(int ops) |
private static DispatchQueue |
pickThreadQueue(HawtDispatcher dispatcher,
DispatchQueue targetQueue) |
private void |
register_on(DispatchQueue queue) |
void |
setCancelHandler(java.lang.Runnable handler)
Deprecated.
|
void |
setCancelHandler(Task cancelHandler)
Sets the cancellation handler task for the given dispatch source.
|
void |
setEventHandler(java.lang.Runnable handler)
Deprecated.
|
void |
setEventHandler(Task eventHandler)
Sets the event handler task of this dispatch source.
|
void |
setTargetQueue(DispatchQueue next)
Sets the target queue for this object.
|
private void |
updateInterest() |
getTargetQueueisSuspended, resume, run, suspendclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetTargetQueueisSuspended, resume, suspendpublic static final boolean DEBUG
final java.nio.channels.SelectableChannel channel
volatile DispatchQueue selectorQueue
final java.util.concurrent.atomic.AtomicBoolean canceled
final int interestOps
Task cancelHandler
Task eventHandler
final java.lang.ThreadLocal<NioDispatchSource.KeyState> keyState
private Task updateInterestTask
public NioDispatchSource(HawtDispatcher dispatcher, java.nio.channels.SelectableChannel channel, int interestOps, DispatchQueue targetQueue)
private static java.lang.String opsToString(int ops)
private static DispatchQueue pickThreadQueue(HawtDispatcher dispatcher, DispatchQueue targetQueue)
protected void onStartup()
onStartup in class BaseSuspendablepublic void cancel()
DispatchSourceAsynchronously cancel the dispatch source, preventing any further invocation of its event handler runnable.
Cancellation prevents any further invocation of the event handler runnable for the specified dispatch source, but does not interrupt an event handler runnable that is already in progress.
The cancellation handler is submitted to the source's target queue once the the source's event handler has finished, indicating it is now safe to close the source's handle.
cancel in interface DispatchSourceDispatchSource.setCancelHandler(Runnable)void internal_cancel()
private NioManager getCurrentNioManager()
private void key_cancel()
private void register_on(DispatchQueue queue)
public void fire(int readyOps)
private void updateInterest()
private boolean isCurrent(DispatchQueue q)
protected void onSuspend()
onSuspend in class BaseSuspendableprotected void onResume()
onResume in class BaseSuspendablepublic boolean isCanceled()
isCanceled in interface DispatchSourceDispatchSource.cancel()@Deprecated public void setCancelHandler(java.lang.Runnable handler)
DispatchSourceSets the cancellation handler runnable for the given dispatch source.
The cancellation handler (if specified) will be submitted to the source's
target queue in response to a call to DispatchSource.cancel() once the
system has released all references to the source's underlying handle and
the source's event handler runnable has returned.
setCancelHandler in interface DispatchSourcehandler - The cancellation handler runnable to submit to the source's target queue.@Deprecated public void setEventHandler(java.lang.Runnable handler)
DispatchSourceSets the event handler runnable of this dispatch source.
setEventHandler in interface DispatchSourcehandler - The event handler runnable to submit to the source's target queue.public void setCancelHandler(Task cancelHandler)
DispatchSourceSets the cancellation handler task for the given dispatch source.
The cancellation handler (if specified) will be submitted to the source's
target queue in response to a call to DispatchSource.cancel() once the
system has released all references to the source's underlying handle and
the source's event handler runnable has returned.
setCancelHandler in interface DispatchSourcecancelHandler - The cancellation handler runnable to submit to the source's target queue.public void setEventHandler(Task eventHandler)
DispatchSourceSets the event handler task of this dispatch source.
setEventHandler in interface DispatchSourceeventHandler - The event handler runnable to submit to the source's target queue.public java.lang.Void getData()
public void setTargetQueue(DispatchQueue next)
DispatchObjectSets the target queue for this object.
An object's target queue is responsible for processing the object.
A dispatch queue's priority is inherited by its target queue. Use the
Dispatch.getGlobalQueue() method to obtain suitable target queue
of the desired priority.
A dispatch source's target queue specifies where its event handler and cancellation handler runnables will be submitted.
setTargetQueue in interface DispatchObjectsetTargetQueue in class AbstractDispatchObjectnext - The new target queue for the object. The queue is retained, and the
previous one, if any, is released.
The result of passing NULL in this parameter is undefined.protected void debug(java.lang.String str,
java.lang.Object... args)
protected void debug(java.lang.Throwable thrown,
java.lang.String str,
java.lang.Object... args)