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

private static final class StoreListeners.ForType<E extends StoreEvent> extends Object
All listeners for a given even type.
  • Field Details

    • type

      final Class<E extends StoreEvent> type
      The types for which listeners have been registered.
    • listeners

      private volatile StoreListener<? super E extends StoreEvent>[] listeners
      The listeners for the event type, or null if none. This is a copy on write array: no elements are modified after an array has been created.
    • next

      final StoreListeners.ForType<?> 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 new next 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, or null if none.
  • Method Details

    • add

      final void add(StoreListener<? super E> listener)
      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

      final boolean remove(StoreListener<? super E> listener)
      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 whole ForType object, but it would require to rebuild the whole listeners chain. It is not worth because this method should never be invoked if callers invoked the StoreListeners.setUsableEventTypes(Class...) at construction time (a recommended practice).
    • hasListener

      final boolean hasListener(StoreListener<?> listener)
      Returns true 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 ExecutionException
      Sends 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.