Listeners are registered once via addListener and then may be invoked by enqueueing and then dispatching events.
The API of this class is designed to make it easy to achieve the following properties
executor.
directExecutor() or be otherwise re-entrant (call back into your
object). So it is important to not call dispatch while holding any locks. This is why
enqueue and dispatch are 2 different methods. It is expected that the decision
to run a particular event is made during the state change, but the decision to actually invoke
the listeners can be delayed slightly so that locks can be dropped. Also, because dispatch is expected to be called concurrently, it is idempotent.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static interface | |
| private static class | ListenerCallQueue.PerListenerQueue<L>
A special purpose queue/executor that dispatches listener events serially on a configured executor. |
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | addListener(L listener, Executor executor)
Adds a listener that will be called using the given executor when events are later |
| public void | dispatch()
Dispatches all events enqueued prior to this call, serially and in order, for every listener. |
| public void | enqueue(ListenerCallQueue.
the callback to execute on eventdispatchEnqueues an event to be run on currently known listeners. |
| public void | enqueue(ListenerCallQueue.
the callback to execute on event,dispatcha description of the event to use in the case of an error label)Enqueues an event to be run on currently known listeners, with a label. |
| private void |
| listeners | back to summary |
|---|---|
| private final List<ListenerCallQueue. | |
| logger | back to summary |
|---|---|
| private static final Logger logger | |
| ListenerCallQueue | back to summary |
|---|---|
| pack-priv ListenerCallQueue() | |
| addListener | back to summary |
|---|---|
| public void addListener(L listener, Executor executor) Adds a listener that will be called using the given executor when events are later | |
| dispatch | back to summary |
|---|---|
| public void dispatch() Dispatches all events enqueued prior to this call, serially and in order, for every listener. Note this method is idempotent and safe to call from any thread | |
| enqueue | back to summary |
|---|---|
| public void enqueue(ListenerCallQueue. Enqueues an event to be run on currently known listeners. The
| |
| enqueue | back to summary |
|---|---|
| public void enqueue(ListenerCallQueue. Enqueues an event to be run on currently known listeners, with a label.
| |
| enqueueHelper | back to summary |
|---|---|
| private void enqueueHelper(ListenerCallQueue. | |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| call | back to summary |
|---|---|
| public void call(L listener) Call a method on the listener. | |
This class is very similar to SequentialExecutor with the exception that events can
be added without necessarily executing immediately.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Executor | |
| pack-priv boolean | |
| pack-priv final Queue | |
| pack-priv final L | |
| pack-priv final Queue |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv synchronized void | |
| pack-priv void | |
| public void |
| executor | back to summary |
|---|---|
| pack-priv final Executor executor | |
| isThreadScheduled | back to summary |
|---|---|
pack-priv boolean isThreadScheduled
| |
| labelQueue | back to summary |
|---|---|
pack-priv final Queue<Object> labelQueue
| |
| listener | back to summary |
|---|---|
| pack-priv final L listener | |
| waitQueue | back to summary |
|---|---|
pack-priv final Queue<ListenerCallQueue.
| |
| PerListenerQueue | back to summary |
|---|---|
| pack-priv PerListenerQueue(L listener, Executor executor) | |
| add | back to summary |
|---|---|
| pack-priv synchronized void add(ListenerCallQueue. Enqueues an event to be run. | |
| dispatch | back to summary |
|---|---|
| pack-priv void dispatch() Dispatches all listeners enqueued prior to this call, serially and in order. | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |