Interface ListenerSubscriber<K,E,O>
- Type Parameters:
K
- the key typeE
- the event typeO
- the order type
public interface ListenerSubscriber<K,E,O>
An interface to subscribe/unsubscribe listeners.
This interface can also be used to get existing listeners.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
An interface for subscribing multiple listeners at once. -
Method Summary
Modifier and TypeMethodDescription@NotNull Collection<SubscribedListener<K,
? extends E, O>> Gets all existingSubscribedListener
s.@NotNull ListenerSubscriber.BulkSubscriber<K,
E, O> Creates a newListenerSubscriber.BulkSubscriber
for subscribing multiple listeners at once.<T extends E>
@NotNull List<SubscribedListener<K,T, O>> listenersFor
(@NotNull Class<T> eventClass) Gets the existingSubscribedListener
s for the specified event.<T extends E>
@NotNull SubscribedListener<K,T, O> Subscribes a new listener for the specified event.<T extends E>
@NotNull SubscribedListener<K,T, O> Subscribes a new listener for the specified event.<T extends E>
@NotNull SubscribedListener<K,T, O> Subscribes a new listener for the specified event.void
unsubscribe
(@NotNull SubscribedListener<K, ? extends E, O> subscribedListener) Unsubscribes the specifiedSubscribedListener
.void
unsubscribeAll
(@NotNull Collection<SubscribedListener<K, ? extends E, O>> subscribedListeners) Unsubscribes the specifiedSubscribedListener
s.void
unsubscribeByKey
(K key) Unsubscribes listeners by the specified key.void
unsubscribeIf
(@NotNull Predicate<SubscribedListener<K, ? extends E, O>> predicate) Unsubscribes all listeners that satisfy the givenPredicate
.
-
Method Details
-
allListeners
Gets all existingSubscribedListener
s.- Returns:
- all existing
SubscribedListener
s
-
listenersFor
@NotNull <T extends E> @NotNull List<SubscribedListener<K,T, listenersForO>> (@NotNull @NotNull Class<T> eventClass) Gets the existingSubscribedListener
s for the specified event.- Type Parameters:
T
- the event type- Parameters:
eventClass
- the class of the event- Returns:
- the existing
SubscribedListener
s for the specified event
-
subscribe
@NotNull <T extends E> @NotNull SubscribedListener<K,T, subscribeO> (@NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Consumer<? super ListenerFactory<K, T, O>> builder) Subscribes a new listener for the specified event.- Type Parameters:
T
- the event type- Parameters:
eventClass
- the class of the eventbuilder
- theConsumer
to modifyListenerFactory
- Returns:
- a
SubscribedListener
-
subscribe
@NotNull <T extends E> @NotNull SubscribedListener<K,T, subscribeO> (@NotNull @NotNull Class<T> eventClass, @NotNull K key, @NotNull @NotNull Consumer<? super T> consumer) Subscribes a new listener for the specified event.- Type Parameters:
T
- the event type- Parameters:
eventClass
- the class of the eventkey
- the keyconsumer
- theConsumer
- Returns:
- a
SubscribedListener
-
subscribe
@NotNull <T extends E> @NotNull SubscribedListener<K,T, subscribeO> (@NotNull @NotNull Class<T> eventClass, @NotNull K key, @NotNull @NotNull Consumer<? super T> consumer, @Nullable O order) Subscribes a new listener for the specified event.- Type Parameters:
T
- the event type- Parameters:
eventClass
- the class of the eventkey
- the keyconsumer
- theConsumer
order
- the order, passingnull
to use a default order- Returns:
- a
SubscribedListener
-
bulkSubscriber
Creates a newListenerSubscriber.BulkSubscriber
for subscribing multiple listeners at once.- Returns:
- a new
ListenerSubscriber.BulkSubscriber
-
unsubscribe
Unsubscribes the specifiedSubscribedListener
.- Parameters:
subscribedListener
- theSubscribedListener
to unsubscribe
-
unsubscribeAll
void unsubscribeAll(@NotNull @NotNull Collection<SubscribedListener<K, ? extends E, O>> subscribedListeners) Unsubscribes the specifiedSubscribedListener
s.- Parameters:
subscribedListeners
- theSubscribedListener
s to unsubscribe
-
unsubscribeByKey
Unsubscribes listeners by the specified key.- Parameters:
key
- the key
-
unsubscribeIf
Unsubscribes all listeners that satisfy the givenPredicate
.- Parameters:
predicate
- a predicate which returns true for listeners to be unsubscribed
-