public final class HawtDispatcher extends java.lang.Object implements Dispatcher
| Modifier and Type | Field and Description |
|---|---|
static java.lang.ThreadLocal<HawtDispatchQueue> |
CURRENT_QUEUE |
(package private) GlobalDispatchQueue |
DEFAULT_QUEUE |
(package private) int |
drains |
private java.lang.Object |
HIGH_MUTEX |
private GlobalDispatchQueue |
HIGH_QUEUE |
(package private) boolean |
jmx |
private java.lang.String |
label |
private java.lang.Object |
LOW_MUTEX |
private GlobalDispatchQueue |
LOW_QUEUE |
private boolean |
profile |
static java.util.WeakHashMap<HawtDispatchQueue,java.lang.Object> |
queues |
(package private) java.util.concurrent.atomic.AtomicInteger |
shutdownState |
private int |
threads |
(package private) TimerThread |
timerThread |
(package private) java.lang.Thread.UncaughtExceptionHandler |
uncaughtExceptionHandler |
| Constructor and Description |
|---|
HawtDispatcher(DispatcherConfig config) |
| Modifier and Type | Method and Description |
|---|---|
(package private) java.lang.String |
assertMessage(java.lang.String label) |
SerialDispatchQueue |
createQueue(java.lang.String label)
Creates a new serial dispatch queue to which runnable objects may be submitted.
|
<Event,MergedEvent> |
createSource(EventAggregator<Event,MergedEvent> aggregator,
DispatchQueue queue)
Creates a new
CustomDispatchSource to monitor events merged into
the dispatch source and automatically submit a handler runnable to a dispatch queue
in response to the events. |
DispatchSource |
createSource(java.nio.channels.SelectableChannel channel,
int interestOps,
DispatchQueue queue)
Creates a new
DispatchSource to monitor SelectableChannel objects and
automatically submit a handler runnable to a dispatch queue in response to events. |
DispatchQueue |
getCurrentQueue()
Returns the queue on which the currently executing runnable is running.
|
ThreadDispatchQueue |
getCurrentThreadQueue() |
DispatchQueue |
getGlobalQueue()
Returns the global concurrent queue of default priority.
|
GlobalDispatchQueue |
getGlobalQueue(DispatchPriority priority)
Returns a well-known global concurrent queue of a given priority level.
|
java.lang.String |
getLabel() |
DispatchQueue[] |
getThreadQueues(DispatchPriority priority) |
java.lang.Thread.UncaughtExceptionHandler |
getUncaughtExceptionHandler() |
java.util.List<Metrics> |
metrics()
Used to get profiling metrics for all the queues
currently being profiled.
|
boolean |
profile() |
void |
profile(boolean on)
If enabled then it enables profiling on the global
queues and any newly created queues.
|
void |
restart()
Restart this dispatcher instance.
|
void |
setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler) |
void |
shutdown()
Shutdown this dispatcher instance.
|
private void |
sleep(long time) |
(package private) void |
track(HawtDispatchQueue queue) |
(package private) void |
untrack(HawtDispatchQueue queue) |
public static final java.lang.ThreadLocal<HawtDispatchQueue> CURRENT_QUEUE
final GlobalDispatchQueue DEFAULT_QUEUE
private final java.lang.Object HIGH_MUTEX
private GlobalDispatchQueue HIGH_QUEUE
private final java.lang.Object LOW_MUTEX
private GlobalDispatchQueue LOW_QUEUE
private final java.lang.String label
volatile TimerThread timerThread
private final int threads
private volatile boolean profile
final int drains
final boolean jmx
final java.util.concurrent.atomic.AtomicInteger shutdownState
volatile java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler
public static final java.util.WeakHashMap<HawtDispatchQueue,java.lang.Object> queues
public HawtDispatcher(DispatcherConfig config)
public void shutdown()
Dispatchershutdown in interface Dispatcherprivate void sleep(long time)
public void restart()
Dispatcherrestart in interface Dispatcherpublic DispatchQueue getGlobalQueue()
DispatcherReturns the global concurrent queue of default priority.
getGlobalQueue in interface DispatcherDispatcher.getGlobalQueue(DispatchPriority)public GlobalDispatchQueue getGlobalQueue(DispatchPriority priority)
DispatcherReturns a well-known global concurrent queue of a given priority level.
The well-known global concurrent queues may not be modified. Calls to
Suspendable.suspend(), Suspendable.resume(), etc., will
have no effect when used with queues returned by this function.
getGlobalQueue in interface Dispatcherpriority - A priority defined in dispatch_queue_priority_tpublic SerialDispatchQueue createQueue(java.lang.String label)
DispatcherCreates a new serial dispatch queue to which runnable objects may be submitted.
Serial dispatch queues execute runnables submitted to them serially in FIFO order. A queue will only invoke one runnable at a time, but independent queues may each execute their runnables concurrently with respect to each other.
Conceptually a dispatch queue may have its own thread of execution, and interaction between queues is highly asynchronous.
createQueue in interface Dispatcherlabel - the label to assign the dispatch queue, can be nullpublic DispatchSource createSource(java.nio.channels.SelectableChannel channel, int interestOps, DispatchQueue queue)
Dispatcher
Creates a new DispatchSource to monitor SelectableChannel objects and
automatically submit a handler runnable to a dispatch queue in response to events.
You are allowed to create multiple dispatch sources to the same SelectableChannel
object.
createSource in interface Dispatcherchannel - the channel to monitor.interestOps - A mask of interest ops (SelectionKey.OP_ACCEPT,
SelectionKey.OP_CONNECT, SelectionKey.OP_READ, or
SelectionKey.OP_WRITE) specifying which events are desired.queue - The dispatch queue to which the event handler tasks will be submited.public <Event,MergedEvent> CustomDispatchSource<Event,MergedEvent> createSource(EventAggregator<Event,MergedEvent> aggregator, DispatchQueue queue)
Dispatcher
Creates a new CustomDispatchSource to monitor events merged into
the dispatch source and automatically submit a handler runnable to a dispatch queue
in response to the events.
createSource in interface Dispatcheraggregator - the data aggregation strategy to use.queue - The dispatch queue to which the event handler tasks will be submited.public java.lang.String getLabel()
public DispatchQueue getCurrentQueue()
DispatcherReturns the queue on which the currently executing runnable is running.
When Dispatcher.getCurrentQueue() is called outside of the context of a
submitted runnable, it will return null.
getCurrentQueue in interface Dispatcherpublic ThreadDispatchQueue getCurrentThreadQueue()
getCurrentThreadQueue in interface Dispatcherpublic DispatchQueue[] getThreadQueues(DispatchPriority priority)
getThreadQueues in interface Dispatchervoid track(HawtDispatchQueue queue)
void untrack(HawtDispatchQueue queue)
public void profile(boolean on)
Dispatcherprofile in interface Dispatcherpublic boolean profile()
profile in interface Dispatcherpublic java.util.List<Metrics> metrics()
Dispatchermetrics in interface Dispatcherjava.lang.String assertMessage(java.lang.String label)
public java.lang.Thread.UncaughtExceptionHandler getUncaughtExceptionHandler()
public void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)