public class ClusteringEventBus extends Object implements EventBus
EventBus
implementation that supports clustering of Event Listeners. Clusters are connected using EventBus Terminals
, which may either distribute Events locally, or remotely.
The separation of EventListeners in clusters allows for a more flexible method of distribution of Events to their
listeners. Some clusters may be connected using a remote distribution mechanism, while other clusters handle their
events asynchronously.Constructor and Description |
---|
ClusteringEventBus()
|
ClusteringEventBus(ClusterSelector clusterSelector)
Initializes a
ClusteringEventBus with the given clusterSelector and a SimpleEventBusTerminal , which dispatches all events to all local clusters synchronously. |
ClusteringEventBus(ClusterSelector clusterSelector,
EventBusTerminal terminal)
Initializes a
ClusteringEventBus with the given clusterSelector and a
terminal . |
ClusteringEventBus(EventBusTerminal terminal)
|
Modifier and Type | Method and Description |
---|---|
void |
publish(EventMessage... events)
Publish a collection of events on this bus (one, or multiple).
|
void |
subscribe(EventListener eventListener)
Subscribe the given
eventListener to this bus. |
void |
unsubscribe(EventListener eventListener)
Unsubscribe the given
eventListener to this bus. |
public ClusteringEventBus()
ClusteringEventBus
with a SimpleEventBusTerminal
and a DefaultClusterSelector
. This causes dispatching to happen synchronously and places all subscribed event
handlers in a single cluster, making its default behavior similar to that of the SimpleEventBus
.public ClusteringEventBus(EventBusTerminal terminal)
ClusteringEventBus
with the given terminal
and a DefaultClusterSelector
. This places all subscribed event handlers in a single cluster. The
terminal
is responsible for publishing incoming events in this cluster.terminal
- The terminal responsible for dispatching events to the clusterspublic ClusteringEventBus(ClusterSelector clusterSelector)
ClusteringEventBus
with the given clusterSelector
and a SimpleEventBusTerminal
, which dispatches all events to all local clusters synchronously.clusterSelector
- The Cluster Selector that chooses the cluster for each of the subscribed event listenerspublic ClusteringEventBus(ClusterSelector clusterSelector, EventBusTerminal terminal)
ClusteringEventBus
with the given clusterSelector
and a
terminal
.clusterSelector
- The Cluster Selector that chooses the cluster for each of the subscribed event listenersterminal
- The terminal responsible for publishing incoming events to each of the clusterspublic void publish(EventMessage... events)
EventBus
events
as a single batch and distribute the events as such to
all subscribed EventListeners.public void subscribe(EventListener eventListener)
EventBus
eventListener
to this bus. When subscribed, it will receive all events
published to this bus.
If the given eventListener
is already subscribed, nothing happens.public void unsubscribe(EventListener eventListener)
EventBus
eventListener
to this bus. When unsubscribed, it will no longer receive
events
published to this bus.unsubscribe
in interface EventBus
eventListener
- The event listener to unsubscribeCopyright © 2010-2014. All Rights Reserved.