org.axonframework.eventhandling.async
Class AsynchronousCluster

java.lang.Object
  extended by org.axonframework.eventhandling.AbstractCluster
      extended by org.axonframework.eventhandling.async.AsynchronousCluster
All Implemented Interfaces:
Cluster

public class AsynchronousCluster
extends AbstractCluster

Cluster implementation that publishes events to the subscribed Event Listeners asynchronously from the publishing thread. This implementation can be configured to retry event when processing fails. Furthermore, a SequencingPolicy will tell the cluster which Events need to be processed sequentially, and which may be processed in parallel from others.

Since:
2.0
Author:
Allard Buijze
See Also:
SequencingPolicy, TransactionManager

Constructor Summary
AsynchronousCluster(String identifier, Executor executor, TransactionManager transactionManager, SequencingPolicy<? super EventMessage<?>> sequencingPolicy)
          Creates an AsynchronousCluster implementation using the given executor, transactionManager and sequencingPolicy.
AsynchronousCluster(String identifier, Executor executor, TransactionManager transactionManager, SequencingPolicy<? super EventMessage<?>> sequencingPolicy, int batchSize, RetryPolicy retryPolicy, int retryInterval)
          Creates an AsynchronousCluster implementation using the given executor, transactionManager and sequencingPolicy.
 
Method Summary
protected  void doPublish(EventMessage<?> message)
          Performs the actual publication of the message to each of the event handlers.
 void publish(EventMessage... events)
          Publishes the given Events to the members of this cluster.
 
Methods inherited from class org.axonframework.eventhandling.AbstractCluster
getMembers, getMetaData, getName, subscribe, unsubscribe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsynchronousCluster

public AsynchronousCluster(String identifier,
                           Executor executor,
                           TransactionManager transactionManager,
                           SequencingPolicy<? super EventMessage<?>> sequencingPolicy)
Creates an AsynchronousCluster implementation using the given executor, transactionManager and sequencingPolicy. Failed events are retried if they are not explicitly non-transient with an interval of 2000 millis. Batch size is 50 events.

Parameters:
identifier - The unique identifier of this cluster
executor - The executor to process event batches with
transactionManager - The TransactionManager that manages transactions around event processing batches
sequencingPolicy - The policy indicating which events must be processed sequentially, and which may be executed in parallel.

AsynchronousCluster

public AsynchronousCluster(String identifier,
                           Executor executor,
                           TransactionManager transactionManager,
                           SequencingPolicy<? super EventMessage<?>> sequencingPolicy,
                           int batchSize,
                           RetryPolicy retryPolicy,
                           int retryInterval)
Creates an AsynchronousCluster implementation using the given executor, transactionManager and sequencingPolicy. Failure is processed according to the given retryPolicy and retryInterval. Processors will process at most batchSize events in a single batch.

Parameters:
identifier - The unique identifier of this cluster
executor - The executor to process event batches with
transactionManager - The TransactionManager that manages transactions around event processing batches
sequencingPolicy - The policy indicating which events must be processed sequentially, and which may be executed in parallel.
batchSize - The number of events to process in a single batch (and transaction)
retryPolicy - The policy to apply when event handling fails
retryInterval - The time (in milliseconds) to wait between retries
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.

Parameters:
events - The Events to publish in the cluster

doPublish

protected void doPublish(EventMessage<?> message)
Performs the actual publication of the message to each of the event handlers. Exceptions thrown by event listeners are caught and are rethrown only after each of the handlers has handled it. In case multiple event listeners throw an exception, the first exception caught is rethrown.

Parameters:
message - The message to publish to each of the handlers


Copyright © 2010-2012. All Rights Reserved.