public interface DispatchSource extends DispatchObject
A dispatch source is used to monitor low-level system objects and automatically submit a handler runnable to a dispatch queue in response to events.
Dispatch sources are not reentrant. Any events received while the dispatch source is suspended or while the event handler runnable is currently executing will be coalesced and delivered after the dispatch source is resumed or the event handler runnable has returned.
Dispatch sources are created in a suspended state. After creating the
source and setting any desired attributes (i.e. the handlers),
a call must be made to the dispatch source's resume()
method
in order to begin event delivery.
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Asynchronously cancel the dispatch source, preventing any further invocation
of its event handler runnable.
|
boolean |
isCanceled() |
void |
setCancelHandler(Runnable handler)
Sets the cancellation handler runnable for the given dispatch source.
|
void |
setCancelHandler(Task task)
Sets the cancellation handler task for the given dispatch source.
|
void |
setEventHandler(Runnable handler)
Sets the event handler runnable of this dispatch source.
|
void |
setEventHandler(Task task)
Sets the event handler task of this dispatch source.
|
getTargetQueue, setTargetQueue
isSuspended, resume, suspend
void setCancelHandler(Runnable handler)
Sets 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 cancel()
once the
system has released all references to the source's underlying handle and
the source's event handler runnable has returned.
handler
- The cancellation handler runnable to submit to the source's target queue.void setEventHandler(Runnable handler)
Sets the event handler runnable of this dispatch source.
handler
- The event handler runnable to submit to the source's target queue.void setCancelHandler(Task task)
Sets 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 cancel()
once the
system has released all references to the source's underlying handle and
the source's event handler runnable has returned.
task
- The cancellation handler runnable to submit to the source's target queue.void setEventHandler(Task task)
Sets the event handler task of this dispatch source.
task
- The event handler runnable to submit to the source's target queue.void cancel()
Asynchronously 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.
setCancelHandler(Runnable)
boolean isCanceled()
cancel()
Copyright © 2010–2017 FuseSource, Corp.. All rights reserved.