org.fusesource.hawtdispatch
Interface DispatchSource

All Superinterfaces:
DispatchObject, Suspendable
All Known Subinterfaces:
CustomDispatchSource<Event,MergedEvent>

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.

Author:
Hiram Chirino

Method Summary
 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.
 
Methods inherited from interface org.fusesource.hawtdispatch.DispatchObject
getTargetQueue, setTargetQueue
 
Methods inherited from interface org.fusesource.hawtdispatch.Suspendable
isSuspended, resume, suspend
 

Method Detail

setCancelHandler

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.

Parameters:
handler - The cancellation handler runnable to submit to the source's target queue.

setEventHandler

void setEventHandler(Runnable handler)

Sets the event handler runnable of this dispatch source.

Parameters:
handler - The event handler runnable to submit to the source's target queue.

setCancelHandler

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.

Parameters:
task - The cancellation handler runnable to submit to the source's target queue.

setEventHandler

void setEventHandler(Task task)

Sets the event handler task of this dispatch source.

Parameters:
task - The event handler runnable to submit to the source's target queue.

cancel

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.

See Also:
setCancelHandler(Runnable)

isCanceled

boolean isCanceled()
Returns:
true if the dispatch source has been canceled.
See Also:
cancel()


Copyright © 2010-2014 FuseSource, Corp.. All Rights Reserved.