Interface EventBus<S,E>
- Type Parameters:
S
- the type of subscribers that can register to the event busE
- the type of events that can be posted to the event bus
public interface EventBus<S,E>
The
EventBus
interface defines the contract for an event bus system that allows objects
to register as subscribers, unregister from receiving events, and post events to all registered
subscribers.-
Method Summary
Modifier and TypeMethodDescriptionRetrieves all currently registered subscriber objects.void
Posts the specified event to all registered subscribers Each subscriber that is interested in the event will receive it.void
Registers the specified subscriber object to the event bus After registration, the subscriber will receive events posted to the bus.void
unregister
(S subscriber) Unregisters the specified subscriber object from the event bus After unregistration, the subscriber will no longer receive events posted to the bus.
-
Method Details
-
register
Registers the specified subscriber object to the event bus After registration, the subscriber will receive events posted to the bus.- Parameters:
subscriber
- the subscriber object to register
-
unregister
Unregisters the specified subscriber object from the event bus After unregistration, the subscriber will no longer receive events posted to the bus.- Parameters:
subscriber
- the subscriber object to unregister
-
post
Posts the specified event to all registered subscribers Each subscriber that is interested in the event will receive it.- Parameters:
event
- the event to post
-
getSubscribers
Collection<S> getSubscribers()Retrieves all currently registered subscriber objects.- Returns:
- a collection of all registered subscriber objects
-