Package org.apache.sis.storage.event
Class StoreListeners.ForType<E extends StoreEvent>
java.lang.Object
org.apache.sis.storage.event.StoreListeners.ForType<E>
- Type Parameters:
E
- the type of events of interest to the listeners.
- Enclosing class:
- StoreListeners
All listeners for a given even type.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StoreListener<? super E>[]
The listeners for the event type, ornull
if none.(package private) final StoreListeners.ForType<?>
Next element in the chain of listeners.The types for which listeners have been registered. -
Constructor Summary
ConstructorsConstructorDescriptionForType
(Class<E> type, StoreListeners.ForType<?> next) Creates a new element in the chained list of listeners. -
Method Summary
Modifier and TypeMethodDescription(package private) final void
add
(StoreListener<? super E> listener) Adds the given listener to the list of listeners for this type.(package private) final int
count()
Returns the number of listeners.(package private) final Map<StoreListener<?>,
Boolean> eventOccured
(E event, Map<StoreListener<?>, Boolean> done) Sends the given event to all listeners registered in this element.(package private) final boolean
hasListener
(StoreListener<?> listener) Returnstrue
if this element contains the given listener.(package private) final boolean
remove
(StoreListener<? super E> listener) Removes a previously registered listener.(package private) static void
removeUnreachables
(StoreListeners.ForType<?> listeners, Set<Class<? extends StoreEvent>> permittedEventTypes) Removes all listeners which will never receive any kind of events.
-
Field Details
-
type
The types for which listeners have been registered. -
listeners
The listeners for the event type, ornull
if none. This is a copy on write array: no elements are modified after an array has been created. -
next
Next element in the chain of listeners. Intentionally final; if we want to remove an element then we need to recreate all previous elements with newnext
values. We do that for avoiding the need to synchronize iterations over the elements.
-
-
Constructor Details
-
ForType
ForType(Class<E> type, StoreListeners.ForType<?> next) Creates a new element in the chained list of listeners.- Parameters:
type
- type of events of interest for listeners in this element.next
- the next element in the chained list, ornull
if none.
-
-
Method Details
-
add
Adds the given listener to the list of listeners for this type. This method does not check if the given listener was already registered; it a listener is registered twice, it will need to be removed twice.It is caller responsibility to perform synchronization and to verify that the listener is non-null.
-
remove
Removes a previously registered listener. It the listener has been registered twice, only the most recent registration is removed.It is caller responsibility to perform synchronization.
- Parameters:
listener
- the listener to remove.- Returns:
true
if the list of listeners is empty after this method call.
-
removeUnreachables
static void removeUnreachables(StoreListeners.ForType<?> listeners, Set<Class<? extends StoreEvent>> permittedEventTypes) Removes all listeners which will never receive any kind of events. Note: ideally we would remove the wholeForType
object, but it would require to rebuild the wholelisteners
chain. It is not worth because this method should never be invoked if callers invoked theStoreListeners.setUsableEventTypes(Class...)
at construction time (a recommended practice). -
hasListener
Returnstrue
if this element contains the given listener. -
count
final int count()Returns the number of listeners. -
eventOccured
final Map<StoreListener<?>,Boolean> eventOccured(E event, Map<StoreListener<?>, Boolean> done) throws ExecutionExceptionSends the given event to all listeners registered in this element.- Parameters:
event
- the event to send to listeners.done
- listeners who were already notified, for avoiding to notify them twice.- Returns:
- the
done
map, created when first needed. - Throws:
ExecutionException
- if at least one listener failed to execute.
-