Top Description Inners Fields Constructors Methods
com.google.common.util.concurrent

pack-priv final Class ListenerCallQueue<L>

extends Object
Class Inheritance
Annotations
@J2ktIncompatible
@GwtIncompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

A list of listeners for implementing a concurrency friendly observable object.

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

The last point is subtle. Often the observable object will be managing its own internal state using a lock, however it is dangerous to dispatch listeners while holding a lock because they might run on the 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
ListenerCallQueue.Event<L>

Method reference-compatible listener event.

private static class
ListenerCallQueue.PerListenerQueue<L>

A special purpose queue/executor that dispatches listener events serially on a configured executor.

Field Summary

Modifier and TypeField and Description
private final List<ListenerCallQueue.PerListenerQueue<L>>
private static final LazyLogger

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addListener(L listener, Executor executor)

Adds a listener that will be called using the given executor when events are later enqueued and dispatched.

public void
dispatch()

Dispatches all events enqueued prior to this call, serially and in order, for every listener.

public void
enqueue(ListenerCallQueue.Event<L>
the callback to execute on dispatch
event
)

Enqueues an event to be run on currently known listeners.

public void
enqueue(ListenerCallQueue.Event<L>
the callback to execute on dispatch
event
,
String
a 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
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

listenersback to summary
private final List<ListenerCallQueue.PerListenerQueue<L>> listeners
loggerback to summary
private static final LazyLogger logger

Constructor Detail

ListenerCallQueueback to summary
pack-priv ListenerCallQueue()

Method Detail

addListenerback to summary
public void addListener(L listener, Executor executor)

Adds a listener that will be called using the given executor when events are later enqueued and dispatched.

dispatchback 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

enqueueback to summary
public void enqueue(ListenerCallQueue.Event<L> event)

Enqueues an event to be run on currently known listeners.

The toString method of the Event itself will be used to describe the event in the case of an error.

Parameters
event:ListenerCallQueue.Event<L>

the callback to execute on dispatch

enqueueback to summary
public void enqueue(ListenerCallQueue.Event<L> event, String label)

Enqueues an event to be run on currently known listeners, with a label.

Parameters
event:ListenerCallQueue.Event<L>

the callback to execute on dispatch

label:String

a description of the event to use in the case of an error

enqueueHelperback to summary
private void enqueueHelper(ListenerCallQueue.Event<L> event, Object label)
com.google.common.util.concurrent back to summary

pack-priv Interface ListenerCallQueue.Event<L>


Method reference-compatible listener event.

Method Summary

Modifier and TypeMethod and Description
public void
call(L listener)

Call a method on the listener.

Method Detail

callback to summary
public void call(L listener)

Call a method on the listener.

com.google.common.util.concurrent back to summary

private final Class ListenerCallQueue.PerListenerQueue<L>

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • com.google.common.util.concurrent.ListenerCallQueue.PerListenerQueue
All Implemented Interfaces
java.lang.Runnable

A special purpose queue/executor that dispatches listener events serially on a configured executor. Each event can be added and dispatched as separate phases.

This class is very similar to SequentialExecutor with the exception that events can be added without necessarily executing immediately.

Field Summary

Modifier and TypeField and Description
pack-priv final Executor
pack-priv boolean
pack-priv final Queue<Object>
pack-priv final L
pack-priv final Queue<ListenerCallQueue.Event<L>>

Constructor Summary

AccessConstructor and Description
pack-priv
PerListenerQueue(L listener, Executor executor)

Method Summary

Modifier and TypeMethod and Description
pack-priv synchronized void
add(ListenerCallQueue.Event<L> event, Object label)

Enqueues an event to be run.

pack-priv void
dispatch()

Dispatches all listeners enqueued prior to this call, serially and in order.

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

executorback to summary
pack-priv final Executor executor
isThreadScheduledback to summary
pack-priv boolean isThreadScheduled
Annotations
@GuardedBy:this
labelQueueback to summary
pack-priv final Queue<Object> labelQueue
Annotations
@GuardedBy:this
listenerback to summary
pack-priv final L listener
waitQueueback to summary
pack-priv final Queue<ListenerCallQueue.Event<L>> waitQueue
Annotations
@GuardedBy:this

Constructor Detail

PerListenerQueueback to summary
pack-priv PerListenerQueue(L listener, Executor executor)

Method Detail

addback to summary
pack-priv synchronized void add(ListenerCallQueue.Event<L> event, Object label)

Enqueues an event to be run.

dispatchback to summary
pack-priv void dispatch()

Dispatches all listeners enqueued prior to this call, serially and in order.

Annotations
@SuppressWarnings:CatchingUnchecked
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
@SuppressWarnings:CatchingUnchecked