| Constructor and Description |
|---|
SimpleEventBus(@NonNull java.lang.Class<E> type) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
eventCancelled(E event)
Returns if a given event instance is currently "cancelled".
|
protected @Nullable java.lang.reflect.Type |
eventGenericType(E event)
Gets the generic
Type of a given event. |
@NonNull java.lang.Class<E> |
eventType()
Gets the event type of the bus.
|
<T extends E> |
hasSubscribers(@NonNull java.lang.Class<T> clazz)
Determines whether or not the specified event has subscribers.
|
@NonNull PostResult |
post(E event)
Posts an event to all registered subscribers.
|
<T extends E> |
register(@NonNull java.lang.Class<T> clazz,
@NonNull EventSubscriber<? super T> subscriber)
Registers the given
subscriber to receive events. |
protected boolean |
shouldPost(E event,
@NonNull EventSubscriber<?> subscriber)
Tests if the
event should be posted to the subscriber. |
@NonNull com.google.common.collect.SetMultimap<java.lang.Class<?>,EventSubscriber<?>> |
subscribers()
Gets an immutable multimap containing all of the subscribers
currently registered.
|
void |
unregister(@NonNull EventSubscriber<?> subscriber)
Unregisters a previously registered
subscriber. |
void |
unregister(@NonNull java.util.function.Predicate<EventSubscriber<?>> predicate)
Unregisters all subscribers matching the
predicate. |
void |
unregisterAll()
Unregisters all subscribers.
|
public SimpleEventBus(@NonNull java.lang.Class<E> type)
public @NonNull java.lang.Class<E> eventType()
EventBusThis is represented by the E type parameter.
protected boolean eventCancelled(E event)
The default implementation of this method uses the
Cancellable interface to determine if an event is cancelled.
event - the eventprotected @Nullable java.lang.reflect.Type eventGenericType(E event)
Type of a given event.
The default implementation of this method uses the
ReifiedEvent interface to read the generic type of
an event.
event - the eventprotected boolean shouldPost(E event, @NonNull EventSubscriber<?> subscriber)
event should be posted to the subscriber.
The default implementation of this method tests for cancellation status and matching event/subscriber generic types.
event - the eventsubscriber - the subscriberpublic @NonNull PostResult post(E event)
EventBuspublic <T extends E> void register(@NonNull java.lang.Class<T> clazz, @NonNull EventSubscriber<? super T> subscriber)
EventBussubscriber to receive events.public void unregister(@NonNull EventSubscriber<?> subscriber)
EventBussubscriber.unregister in interface EventBus<E>subscriber - the subscriberpublic void unregister(@NonNull java.util.function.Predicate<EventSubscriber<?>> predicate)
EventBuspredicate.unregister in interface EventBus<E>predicate - the predicate to test subscribers for removalpublic void unregisterAll()
EventBusunregisterAll in interface EventBus<E>public <T extends E> boolean hasSubscribers(@NonNull java.lang.Class<T> clazz)
EventBushasSubscribers in interface EventBus<E>T - the event typeclazz - the event clazzpublic @NonNull com.google.common.collect.SetMultimap<java.lang.Class<?>,EventSubscriber<?>> subscribers()
EventBusEach subscriber is mapped to the type defined when it was
initially registered.
subscribers in interface EventBus<E>