org.axonframework.eventhandling.annotation
Class AnnotationEventListenerAdapter

java.lang.Object
  extended by org.axonframework.eventhandling.annotation.AnnotationEventListenerAdapter
All Implemented Interfaces:
EventListener, EventListenerProxy, TransactionManager, Subscribable

public class AnnotationEventListenerAdapter
extends Object
implements Subscribable, EventListenerProxy, TransactionManager

Adapter that turns any bean with EventHandler annotated methods into an EventListener.

If the event listener has the AsynchronousEventListener annotation, it is also configured to handle events asynchronously. In that case, event processing is handed over to the given Executor.

Since:
0.1
Author:
Allard Buijze
See Also:
EventListener, AsynchronousEventHandlerWrapper

Constructor Summary
AnnotationEventListenerAdapter(Object annotatedEventListener, EventBus eventBus)
          Initialize the AnnotationEventListenerAdapter for the given annotatedEventListener.
AnnotationEventListenerAdapter(Object annotatedEventListener, Executor executor, EventBus eventBus)
          Initialize the AnnotationEventListenerAdapter for the given annotatedEventListener.
 
Method Summary
 void afterTransaction(TransactionStatus transactionStatus)
          Invoked by the EventProcessingScheduler after a series of events is processed.
 void beforeTransaction(TransactionStatus transactionStatus)
          Invoked by the EventProcessingScheduler before processing a series of events.
 Object getTarget()
          Returns the instance that this proxy delegates all event handling to
 void handle(Event event)
          Process the given event.
 void subscribe()
          Subscribe the EventListener with the configured EventBus.
 void unsubscribe()
          Unsubscribe the EventListener with the configured EventBus.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationEventListenerAdapter

public AnnotationEventListenerAdapter(Object annotatedEventListener,
                                      EventBus eventBus)
Initialize the AnnotationEventListenerAdapter for the given annotatedEventListener. When the adapter subscribes, it will subscribe to the given event bus.

Parameters:
annotatedEventListener - the event listener
eventBus - the event bus to register the event listener to

AnnotationEventListenerAdapter

public AnnotationEventListenerAdapter(Object annotatedEventListener,
                                      Executor executor,
                                      EventBus eventBus)
Initialize the AnnotationEventListenerAdapter for the given annotatedEventListener. If the annotatedEventListener is asynchronous (has the AsynchronousEventListener) annotation) then the given executor is used to execute event processing.

Parameters:
annotatedEventListener - the event listener
executor - The executor to use when wiring an Asynchronous Event Listener.
eventBus - the event bus to register the event listener to
Method Detail

handle

public void handle(Event event)
Process the given event. The implementation may decide to process or skip the given event. It is highly unrecommended to throw any exception during the event handling process.

Specified by:
handle in interface EventListener
Parameters:
event - the event to handle

beforeTransaction

public void beforeTransaction(TransactionStatus transactionStatus)
Invoked by the EventProcessingScheduler before processing a series of events. The given TransactionStatus may be used to set the maximum batch size for the current transaction.

Specified by:
beforeTransaction in interface TransactionManager
Parameters:
transactionStatus - The current status of the transaction
See Also:
TransactionManager.afterTransaction(TransactionStatus), TransactionStatus

afterTransaction

public void afterTransaction(TransactionStatus transactionStatus)
Invoked by the EventProcessingScheduler after a series of events is processed. The given TransactionStatus may be used to indicate whether the scheduler should yield to other event processing schedulers or not.

This method is always called once for each invocation to TransactionManager.beforeTransaction(TransactionStatus), even if no events were processed at all.

Note that this method is called when a transactional batch was handled successfully, as well as when an error occurred. Use the TransactionStatus object to find information about transaction status and (when failed) the cause of the failure.

Specified by:
afterTransaction in interface TransactionManager
Parameters:
transactionStatus - The current status of the transaction
See Also:
TransactionManager.beforeTransaction(TransactionStatus), TransactionStatus

unsubscribe

@PreDestroy
public void unsubscribe()
Unsubscribe the EventListener with the configured EventBus.

Specified by:
unsubscribe in interface Subscribable

subscribe

@PostConstruct
public void subscribe()
Subscribe the EventListener with the configured EventBus.

Specified by:
subscribe in interface Subscribable

getTarget

public Object getTarget()
Description copied from interface: EventListenerProxy
Returns the instance that this proxy delegates all event handling to

Specified by:
getTarget in interface EventListenerProxy
Returns:
the instance that this proxy delegates all event handling to


Copyright © 2011. All Rights Reserved.