org.axonframework.eventhandling
Class AbstractCluster

java.lang.Object
  extended by org.axonframework.eventhandling.AbstractCluster
All Implemented Interfaces:
Cluster, EventProcessingMonitorSupport
Direct Known Subclasses:
AsynchronousCluster, SimpleCluster

public abstract class AbstractCluster
extends Object
implements Cluster

Abstract Cluster implementation that keeps track of Cluster members (EventListeners). This implementation is thread-safe. The getMembers() method returns a read-only runtime view of the members in the cluster.

Since:
1.2
Author:
Allard Buijze

Constructor Summary
protected AbstractCluster(String name)
          Initializes the cluster with given name.
protected AbstractCluster(String name, Comparator<EventListener> comparator)
          Initializes the cluster with given name, using given comparator to order the listeners in the cluster.
 
Method Summary
protected abstract  void doPublish(List<EventMessage> events, Set<EventListener> eventListeners, MultiplexingEventProcessingMonitor eventProcessingMonitor)
          Publish the given list of events to the given set of eventListeners, and notify the given eventProcessingMonitor after completion.
 Set<EventListener> getMembers()
          Returns a read-only view on the members in the cluster.
 ClusterMetaData getMetaData()
          Returns the MetaData of this Cluster.
 String getName()
          Returns the name of this cluster.
 void publish(EventMessage... events)
          Publishes the given Events to the members of this cluster.
 void subscribe(EventListener eventListener)
          Subscribe the given eventListener to this cluster.
 void subscribeEventProcessingMonitor(EventProcessingMonitor monitor)
          Subscribes the given monitor.
 void unsubscribe(EventListener eventListener)
          Unsubscribes the given eventListener from this cluster.
 void unsubscribeEventProcessingMonitor(EventProcessingMonitor monitor)
          Unsubscribed the given monitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCluster

protected AbstractCluster(String name)
Initializes the cluster with given name. The order in which listeners are organized in the cluster is undefined.

Parameters:
name - The name of this cluster

AbstractCluster

protected AbstractCluster(String name,
                          Comparator<EventListener> comparator)
Initializes the cluster with given name, using given comparator to order the listeners in the cluster. The order of invocation of the members in this cluster is according the order provided by the comparator.

Parameters:
name - The name of this cluster
comparator - The comparator providing the ordering of the Event Listeners
Method Detail

publish

public void publish(EventMessage... events)
Description copied from interface: Cluster
Publishes the given Events to the members of this cluster.

Implementations may do this synchronously or asynchronously. Although EventListeners are discouraged to throw exceptions, it is possible that they are propagated through this method invocation. In that case, no guarantees can be given about the delivery of Events at all Cluster members.

Specified by:
publish in interface Cluster
Parameters:
events - The Events to publish in the cluster

doPublish

protected abstract void doPublish(List<EventMessage> events,
                                  Set<EventListener> eventListeners,
                                  MultiplexingEventProcessingMonitor eventProcessingMonitor)
Publish the given list of events to the given set of eventListeners, and notify the given eventProcessingMonitor after completion. The given set of eventListeners is a live view on the memberships of the cluster. Any subscription changes are immediately visible in this set. Iterators created on the set iterate over an immutable view reflecting the state at the moment the iterator was created.

When this method is invoked as part of a Unit of Work (see CurrentUnitOfWork.isStarted()), the monitor invocation should be postponed until the Unit of Work is committed or rolled back, to ensure any transactions are properly propagated when the monitor is invoked.

It is the implementation's responsibility to ensure that –eventually– the each of the given events is provided to the eventProcessingMonitor, either to the EventProcessingMonitor.onEventProcessingCompleted(java.util.List) or the EventProcessingMonitor.onEventProcessingFailed(java.util.List, Throwable) method.

Parameters:
events - The events to publish
eventListeners - The event listeners subscribed at the moment the event arrived
eventProcessingMonitor - The monitor to notify after completion.

getName

public String getName()
Description copied from interface: Cluster
Returns the name of this cluster. This name is used to detect distributed instances of the same cluster. Multiple instances referring to the same logical cluster (on different JVM's) must have the same name.

Specified by:
getName in interface Cluster
Returns:
the name of this cluster

subscribe

public void subscribe(EventListener eventListener)
Description copied from interface: Cluster
Subscribe the given eventListener to this cluster. If the listener is already subscribed, nothing happens.

While the Event Listeners is subscribed, it will receive all messages published to the cluster.

Specified by:
subscribe in interface Cluster
Parameters:
eventListener - the Event Listener instance to subscribe

unsubscribe

public void unsubscribe(EventListener eventListener)
Description copied from interface: Cluster
Unsubscribes the given eventListener from this cluster. If the listener is already unsubscribed, or was never subscribed, nothing happens.

Specified by:
unsubscribe in interface Cluster
Parameters:
eventListener - the Event Listener instance to unsubscribe

getMetaData

public ClusterMetaData getMetaData()
Description copied from interface: Cluster
Returns the MetaData of this Cluster.

Specified by:
getMetaData in interface Cluster
Returns:
the MetaData of this Cluster

getMembers

public Set<EventListener> getMembers()
Returns a read-only view on the members in the cluster. This view may be updated by the Cluster when members subscribe or unsubscribe. Cluster implementations may also return the view representing the state at the moment this method is invoked.

This implementation returns a real-time view on the actual members, which changes when members join or leave the cluster. Iterators created from the returned set are thread-safe and iterate over the members available at the time the iterator was created. The iterator does not allow the Iterator.remove() method to be invoked.

Specified by:
getMembers in interface Cluster
Returns:
a view of the members of this cluster

subscribeEventProcessingMonitor

public void subscribeEventProcessingMonitor(EventProcessingMonitor monitor)
Description copied from interface: EventProcessingMonitorSupport
Subscribes the given monitor. If the monitor is already subscribed, nothing happens.

Specified by:
subscribeEventProcessingMonitor in interface EventProcessingMonitorSupport
Parameters:
monitor - The monitor to subscribe

unsubscribeEventProcessingMonitor

public void unsubscribeEventProcessingMonitor(EventProcessingMonitor monitor)
Description copied from interface: EventProcessingMonitorSupport
Unsubscribed the given monitor. If the monitor was not subscribed, or was already unsubscribed, nothing happens.

Specified by:
unsubscribeEventProcessingMonitor in interface EventProcessingMonitorSupport
Parameters:
monitor - The monitor to unsubscribe


Copyright © 2010-2016. All Rights Reserved.