public interface PerformanceListenerStore extends DefaultListenerStore
DefaultListenerStore which offers to enable higher
ListenerStore.get(Class) performance. The higher performance is achieved at the
cost of lowering the performance of ListenerStore.remove(Class, Listener) and
ListenerStore.add(Class, Listener).
Most applications have something like a setup phase in which listeners are registered. After this phase, the listener store is rarely modified anymore, but events will be fired frequently from now on. If this reflects your usage scenario, this ListenerStore implementation can offer higher runtime performance.
After instantiation, this store behaves exactly like the
DefaultListenerStore. After the registration phase of your
application is finished, you may call optimizeGet() on this store.
This will replace all regular Lists which are used to store different
listeners with CopyOnWriteArrayLists. This
reduces the need to copy the list of retrieved Listeners upon
ListenerStore.get(Class). The cost of copying is thereby moved to the
ListenerStore.add(Class, Listener) and ListenerStore.remove(Class, Listener) methods.
| Modifier and Type | Method and Description |
|---|---|
static PerformanceListenerStore |
create()
Creates a new default PerformanceListenerStore.
|
boolean |
isAutoOptimize()
Whether auto optimization upon first call to
ListenerStore.get(Class) has been
enabled in the constructor. |
boolean |
isOptimized()
Whether
optimizeGet() has been called on this store. |
void |
optimizeGet()
Interchanges the performance characteristics of
ListenerStore.get(Class) with
ListenerStore.add(Class, Listener) resp. |
static PerformanceListenerStore |
withAutoOptimize()
Creates a new PerformanceListenerStore with the auto optimize flag set to
true.
|
add, add, clearAll, clearAll, close, get, isSequential, remove, remove, synchronizedViewstatic PerformanceListenerStore create()
create in interface DefaultListenerStorestatic PerformanceListenerStore withAutoOptimize()
optimizeGet()
method the first time its ListenerStore.get(Class) method is called.boolean isAutoOptimize()
ListenerStore.get(Class) has been
enabled in the constructor.boolean isOptimized()
optimizeGet() has been called on this store.optimizeGet() has been called on this store.void optimizeGet()
ListenerStore.get(Class) with
ListenerStore.add(Class, Listener) resp. ListenerStore.remove(Class, Listener).
This will store all currently registered listeners into
CopyOnWriteArrayLists. Thus, after calling
this method, the add and remove methods will always copy
the internal array of the respective listener list. In return, the
ListenerStore.get(Class) method does not need to create a copy of the
retrieved listener list to achieve concurrency safety. Therefore, after
calling this method
add and remove perform in O(n).clear, clearAll and thus close perform in
O(n²).get performs in O(1).
Where n is the number of listeners registered for a listener
class.
This method may only be called once. Subsequent calls will have no
effect. The internal modifications done by this method can not be
reverted. Whether this method has already been called can be queried with
isOptimized().
Copyright © 2014–2015. All rights reserved.