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, EventProcessingMonitorSupport

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, SequencingPolicy<? super EventMessage<?>> sequencingPolicy)
          Creates an AsynchronousCluster implementation using the given executor and sequencingPolicy.
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, ErrorHandler errorHandler)
          Creates an AsynchronousCluster implementation using the given executor, transactionManager and sequencingPolicy.
AsynchronousCluster(String name, Executor executor, UnitOfWorkFactory unitOfWorkFactory, SequencingPolicy<? super EventMessage<?>> sequencingPolicy, ErrorHandler errorHandler)
          Creates an AsynchronousCluster implementation using the given executor, unitOfWorkFactory and sequencingPolicy.
AsynchronousCluster(String name, Executor executor, UnitOfWorkFactory unitOfWorkFactory, SequencingPolicy<? super EventMessage<?>> sequencingPolicy, ErrorHandler errorHandler, OrderResolver orderResolver)
          Creates an AsynchronousCluster implementation using the given executor, unitOfWorkFactory and sequencingPolicy.
 
Method Summary
protected  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.
protected  EventProcessor newProcessingScheduler(EventProcessor.ShutdownCallback shutDownCallback, Set<EventListener> eventListeners, MultiplexingEventProcessingMonitor eventProcessingMonitor)
          Creates a new scheduler instance that schedules tasks on the executor service for the managed EventListener.
protected  void schedule(EventMessage<?> task, MultiplexingEventProcessingMonitor eventProcessingMonitor)
          Schedules this task for execution when all pre-conditions have been met.
 
Methods inherited from class org.axonframework.eventhandling.AbstractCluster
getMembers, getMetaData, getName, publish, subscribe, subscribeEventProcessingMonitor, unsubscribe, unsubscribeEventProcessingMonitor
 
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 2 seconds.

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,
                           SequencingPolicy<? super EventMessage<?>> sequencingPolicy)
Creates an AsynchronousCluster implementation using the given executor and sequencingPolicy. Each handler will receive each event once, ignoring exceptions they may throw. The Unit of Work in which Events are handled is not backed by any Transaction Manager.

Parameters:
identifier - The unique identifier of this cluster
executor - The executor to process event batches with
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,
                           ErrorHandler errorHandler)
Creates an AsynchronousCluster implementation using the given executor, transactionManager and sequencingPolicy. Failures are processed by the given errorHandler.

The Cluster is initialized with a DefaultUnitOfWorkFactory, using the given transactionManager to manage the backing transactions.

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.
errorHandler - The handler that handles error during event processing

AsynchronousCluster

public AsynchronousCluster(String name,
                           Executor executor,
                           UnitOfWorkFactory unitOfWorkFactory,
                           SequencingPolicy<? super EventMessage<?>> sequencingPolicy,
                           ErrorHandler errorHandler)
Creates an AsynchronousCluster implementation using the given executor, unitOfWorkFactory and sequencingPolicy. Failures are processed by the given errorHandler.

If transactions are required, the given unitOfWorkFactory should be configured to create Transaction backed Unit of Work instances.

Parameters:
name - The unique identifier of this cluster
executor - The executor to process event batches with
unitOfWorkFactory - The Unit of Work Factory Manager that manages Units of Work around event processing
sequencingPolicy - The policy indicating which events must be processed sequentially, and which may be executed in parallel.
errorHandler - The handler that handles error during event processing

AsynchronousCluster

public AsynchronousCluster(String name,
                           Executor executor,
                           UnitOfWorkFactory unitOfWorkFactory,
                           SequencingPolicy<? super EventMessage<?>> sequencingPolicy,
                           ErrorHandler errorHandler,
                           OrderResolver orderResolver)
Creates an AsynchronousCluster implementation using the given executor, unitOfWorkFactory and sequencingPolicy. Failures are processed by the given errorHandler. Event Listeners are invoked in the order provided by the orderResolver.

If transactions are required, the given unitOfWorkFactory should be configured to create Transaction backed Unit of Work instances.

Event Listeners with the lowest order are invoked first.

Parameters:
name - The unique identifier of this cluster
executor - The executor to process event batches with
unitOfWorkFactory - The Unit of Work Factory Manager that manages Units of Work around event processing
sequencingPolicy - The policy indicating which events must be processed sequentially, and which may be executed in parallel.
errorHandler - The handler that handles error during event processing
orderResolver - The resolver providing the expected order of the listeners
Method Detail

doPublish

protected void doPublish(List<EventMessage> events,
                         Set<EventListener> eventListeners,
                         MultiplexingEventProcessingMonitor eventProcessingMonitor)
Description copied from class: AbstractCluster
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.

Specified by:
doPublish in class AbstractCluster
Parameters:
events - The events to publish
eventListeners - The event listeners subscribed at the moment the event arrived
eventProcessingMonitor - The monitor to notify after completion.

schedule

protected void schedule(EventMessage<?> task,
                        MultiplexingEventProcessingMonitor eventProcessingMonitor)
Schedules this task for execution when all pre-conditions have been met.

Parameters:
task - The task to schedule for processing.
eventProcessingMonitor - The monitor to invoke after completion

newProcessingScheduler

protected EventProcessor newProcessingScheduler(EventProcessor.ShutdownCallback shutDownCallback,
                                                Set<EventListener> eventListeners,
                                                MultiplexingEventProcessingMonitor eventProcessingMonitor)
Creates a new scheduler instance that schedules tasks on the executor service for the managed EventListener.

Parameters:
shutDownCallback - The callback that needs to be notified when the scheduler stops processing.
eventListeners - The listeners to process the event with
eventProcessingMonitor - @return a new scheduler instance
Returns:
The processing scheduler created


Copyright © 2010-2016. All Rights Reserved.