Package org.hibernate.event.service.spi
Interface EventListenerGroup<T>
-
public interface EventListenerGroup<T>
Contract for a groups of events listeners for a particular event type.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addDuplicationStrategy(DuplicationStrategy strategy)
Mechanism to more finely control the notion of duplicates.void
appendListener(T listener)
void
appendListeners(T... listeners)
void
clear()
Deprecated.likely want to useclearListeners()
instead, which doesn't also reset the registered DuplicationStrategy(ies).void
clearListeners()
Removes all registered listenersint
count()
<U> void
fireEventOnEachListener(U event, BiConsumer<T,U> actionOnEvent)
Similar asfireLazyEventOnEachListener(Supplier, BiConsumer)
except it doesn't use a {Supplier
}: useful when there is no need to lazily initialize the event.<R,U,RL>
CompletionStage<R>fireEventOnEachListener(U event, Function<RL,Function<U,CompletionStage<R>>> fun)
Similar tofireEventOnEachListener(Object, Function)
, but Reactive friendly: it chains processing of the same event on each Reactive Listener, and returns aCompletionStage
of type R.<R,U,RL,X>
CompletionStage<R>fireEventOnEachListener(U event, X param, Function<RL,BiFunction<U,X,CompletionStage<R>>> fun)
Similar tofireEventOnEachListener(Object, Object, Function)
, but Reactive friendly: it chains processing of the same event on each Reactive Listener, and returns aCompletionStage
of type R.<U,X>
voidfireEventOnEachListener(U event, X param, EventActionWithParameter<T,U,X> actionOnEvent)
Similar tofireEventOnEachListener(Object, BiConsumer)
, but allows passing a third parameter to the consumer; our code based occasionally needs a third parameter: having this additional variant allows using the optimal iteration more extensively and reduce allocations.<U> void
fireLazyEventOnEachListener(Supplier<U> eventSupplier, BiConsumer<T,U> actionOnEvent)
Fires an event on each registered event listener of this group.<R,U,RL>
CompletionStage<R>fireLazyEventOnEachListener(Supplier<U> eventSupplier, Function<RL,Function<U,CompletionStage<R>>> fun)
Similar tofireLazyEventOnEachListener(Supplier, BiConsumer)
, but Reactive friendly: it chains processing of the same event on each Reactive Listener, and returns aCompletionStage
of type R.EventType<T>
getEventType()
Retrieve the event type associated with this groups of listeners.boolean
isEmpty()
Are there no listeners registered?Iterable<T>
listeners()
Deprecated.this is not the most efficient way for iterating the event listeners.void
prependListener(T listener)
void
prependListeners(T... listeners)
-
-
-
Method Detail
-
getEventType
EventType<T> getEventType()
Retrieve the event type associated with this groups of listeners.- Returns:
- The event type.
-
isEmpty
boolean isEmpty()
Are there no listeners registered?- Returns:
- true if no listeners are registered; false otherwise.
-
count
int count()
-
listeners
@Deprecated Iterable<T> listeners()
Deprecated.this is not the most efficient way for iterating the event listeners. SeefireEventOnEachListener(Object, BiConsumer)
and its overloaded variants for better alternatives.- Returns:
- The Iterable.
-
addDuplicationStrategy
void addDuplicationStrategy(DuplicationStrategy strategy)
Mechanism to more finely control the notion of duplicates.For example, say you are registering listeners for an extension library. This extension library could define a "marker interface" which indicates listeners related to it and register a strategy that checks against that marker interface.
- Parameters:
strategy
- The duplication strategy
-
appendListener
void appendListener(T listener)
-
appendListeners
void appendListeners(T... listeners)
-
prependListener
void prependListener(T listener)
-
prependListeners
void prependListeners(T... listeners)
-
clear
@Deprecated void clear()
Deprecated.likely want to useclearListeners()
instead, which doesn't also reset the registered DuplicationStrategy(ies).Clears both the list of event listeners and all DuplicationStrategy, including the default duplication strategy.
-
clearListeners
void clearListeners()
Removes all registered listeners
-
fireLazyEventOnEachListener
@Incubating <U> void fireLazyEventOnEachListener(Supplier<U> eventSupplier, BiConsumer<T,U> actionOnEvent)
Fires an event on each registered event listener of this group. Implementation note (performance): the first argument is a supplier so that events can avoid being created when no listener is registered. the second argument is specifically designed to avoid needing a capturing lambda.- Type Parameters:
U
- the kind of event
-
fireEventOnEachListener
@Incubating <U> void fireEventOnEachListener(U event, BiConsumer<T,U> actionOnEvent)
Similar asfireLazyEventOnEachListener(Supplier, BiConsumer)
except it doesn't use a {Supplier
}: useful when there is no need to lazily initialize the event.- Type Parameters:
U
- the kind of event
-
fireEventOnEachListener
@Incubating <U,X> void fireEventOnEachListener(U event, X param, EventActionWithParameter<T,U,X> actionOnEvent)
Similar tofireEventOnEachListener(Object, BiConsumer)
, but allows passing a third parameter to the consumer; our code based occasionally needs a third parameter: having this additional variant allows using the optimal iteration more extensively and reduce allocations.
-
fireEventOnEachListener
@Incubating <R,U,RL> CompletionStage<R> fireEventOnEachListener(U event, Function<RL,Function<U,CompletionStage<R>>> fun)
Similar tofireEventOnEachListener(Object, Function)
, but Reactive friendly: it chains processing of the same event on each Reactive Listener, and returns aCompletionStage
of type R. The various generic types allow using this for each concrete event type and flexible return types.Used by Hibernate Reactive
- Type Parameters:
R
- the return type of the returned CompletionStageU
- the type of the event being fired on each listenerRL
- the type of ReactiveListener: each listener of type T will be casted to it.- Parameters:
event
- The event being firedfun
- The function combining each event listener with the event- Returns:
- the composite completion stage of invoking fun(event) on each listener.
-
fireEventOnEachListener
@Incubating <R,U,RL,X> CompletionStage<R> fireEventOnEachListener(U event, X param, Function<RL,BiFunction<U,X,CompletionStage<R>>> fun)
Similar tofireEventOnEachListener(Object, Object, Function)
, but Reactive friendly: it chains processing of the same event on each Reactive Listener, and returns aCompletionStage
of type R. The various generic types allow using this for each concrete event type and flexible return types.Used by Hibernate Reactive
- Type Parameters:
R
- the return type of the returned CompletionStageU
- the type of the event being fired on each listenerRL
- the type of ReactiveListener: each listener of type T will be casted to it.X
- an additional parameter to be passed to the function fun- Parameters:
event
- The event being firedfun
- The function combining each event listener with the event- Returns:
- the composite completion stage of invoking fun(event) on each listener.
-
fireLazyEventOnEachListener
@Incubating <R,U,RL> CompletionStage<R> fireLazyEventOnEachListener(Supplier<U> eventSupplier, Function<RL,Function<U,CompletionStage<R>>> fun)
Similar tofireLazyEventOnEachListener(Supplier, BiConsumer)
, but Reactive friendly: it chains processing of the same event on each Reactive Listener, and returns aCompletionStage
of type R. The various generic types allow using this for each concrete event type and flexible return types.This variant expects a Supplier of the event, rather than the event directly; this is useful for the event types which are commonly configured with no listeners at all, so to allow skipping creating the event; use only for event types which are known to be expensive while the listeners are commonly empty.
Used by Hibernate Reactive
- Type Parameters:
R
- the return type of the returned CompletionStageU
- the type of the event being fired on each listenerRL
- the type of ReactiveListener: each listener of type T will be casted to it.- Parameters:
eventSupplier
- A supplier able to produce the actual eventfun
- The function combining each event listener with the event- Returns:
- the composite completion stage of invoking fun(event) on each listener.
-
-