public interface PriorityListenerStore extends ListenerStore
ListenerStore implementation which provides Listener
prioritization upon registering. When registering a Listener with
this store, you may use an overload of add
to specify a priority for the Listener. The lower the priority, the sooner
the Listener will be notified when an Event is dispatched for its listener
class. When using the normal add method, the
Listener is assigned a default priority which may be specified in the
constructor. The public interface to this store is thread safe.
Performance notes: This store uses a HashMap of LinkedLists to manage the Listeners and inserts Listeners sorted by priority
upon registering. Thus, adding a Listener as well as removing one performs in
O(n), where n is the number of Listeners registered for the
class for which the Listener should be added/removed. The get method retrieves the stored listeners from a map in O(1) but
then needs to create a copy of this list in order to avoid concurrency
problems. It therefore performs in O(n).
| Modifier and Type | Method and Description |
|---|---|
<T extends Listener> |
add(Class<T> listenerClass,
T listener)
Adds a listener with the default priority specified in the constructor.
|
<T extends Listener> |
add(Class<T> listenerClass,
T listener,
int priority)
Adds a listener with the given priority.
|
static PriorityListenerStore |
create()
Creates a new PriorityListenerStore with default priority of
0. |
static PriorityListenerStore |
create(int defaultPriority)
Creates a new PriorityListenerStore with the given default priority.
|
PriorityListenerStore |
synchronizedView()
Returns a thread safe view of this store.
|
add, clearAll, clearAll, close, get, isSequential, remove, removestatic PriorityListenerStore create()
0.static PriorityListenerStore create(int defaultPriority)
defaultPriority - The default priority to assign to listeners which
have been registered using add(Class, Listener).PriorityListenerStore synchronizedView()
ListenerStoreReturns a thread safe view of this store. The returned store will be backed by this one, thus changes on the one object are automatically reflected to the other. This also implies that unsynchronized access is still possible through the original object.
Subsequent calls to this method must return a cached instance of the
synchronized view. Store implementations that are natively thread safe
may simply return this.
Note: The actual returned object must be assignment compatible with this store, thus for the implementation 'MyListenerStore' the following statement must compile:
MyListenerStore store = new MyListenerStore().synchronizedView();
synchronizedView in interface ListenerStore<T extends Listener> void add(Class<T> listenerClass, T listener)
onRegister method gets
called to notify the listener about being added to a new parent. The
onRegister method is not subject to the dispatching strategy
implemented by this EventProvider and is called from the current
thread.
Note on concurrency: This method can safely be called from within a listening method during event handling to add a listener. This will have no impact on the current event delegation process.
add in interface ListenerStoreT - Type of the listener to add.listenerClass - The class representing the event(s) to listen on.listener - The listener to add.IllegalArgumentException - If either listenerClass or listener
argument is null.<T extends Listener> void add(Class<T> listenerClass, T listener, int priority)
onRegister
method gets called to notify the listener about being added to a new
parent. The onRegister method is not subject to the dispatching
strategy implemented by this EventProvider and is called from the
current thread.
Note on concurrency: This method can safely be called from within a listening method during event handling to add a listener. This will have no impact on the current event delegation process.
T - Type of the listener to add.listenerClass - The class representing the event(s) to listen on.listener - The listener to add.priority - The priority of the new listener.IllegalArgumentException - If either listenerClass or listener
argument is null.Copyright © 2014–2015. All rights reserved.