org.axonframework.eventhandling.annotation
Class AnnotationEventListenerAdapter

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

public class AnnotationEventListenerAdapter
extends Object
implements Subscribable, EventListenerProxy

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

Since:
0.1
Author:
Allard Buijze
See Also:
EventListener

Constructor Summary
AnnotationEventListenerAdapter(Object annotatedEventListener, EventBus eventBus)
          Initialize the AnnotationEventListenerAdapter for the given annotatedEventListener.
 
Method Summary
 Class<?> getTargetType()
          Returns the instance type that this proxy delegates all event handling to.
 void handle(EventMessage event)
          Process the given event.
 void subscribe()
          Subscribe the EventListener with the configured EventBus.
static AnnotationEventListenerAdapter subscribe(Object annotatedEventListener, EventBus eventBus)
          Subscribe the given annotatedEventListener to the given 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
Method Detail

subscribe

public static AnnotationEventListenerAdapter subscribe(Object annotatedEventListener,
                                                       EventBus eventBus)
Subscribe the given annotatedEventListener to the given eventBus.

Parameters:
annotatedEventListener - The annotated event listener
eventBus - The event bus to subscribe to
Returns:
an AnnotationEventListenerAdapter that wraps the listener. Can be used to unsubscribe.

handle

public void handle(EventMessage 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

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

getTargetType

public Class<?> getTargetType()
Description copied from interface: EventListenerProxy
Returns the instance type that this proxy delegates all event handling to.

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


Copyright © 2010-2012. All Rights Reserved.