org.axonframework.eventhandling.annotation
Class AnnotationEventListenerAdapter

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

public class AnnotationEventListenerAdapter
extends Object
implements Subscribable, EventListenerProxy, ReplayAware

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)
          Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus.
AnnotationEventListenerAdapter(Object annotatedEventListener, EventBus eventBus)
          Deprecated. Use AnnotationEventListenerAdapter(Object) and subscribe the listener to the event bus using EventBus.subscribe(org.axonframework.eventhandling.EventListener)
AnnotationEventListenerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory)
          Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus.
 
Method Summary
 void afterReplay()
          Invoked when a replay has finished.
 void beforeReplay()
          Invoked when a replay is started.
 Class<?> getTargetType()
          Returns the instance type that this proxy delegates all event handling to.
 void handle(EventMessage event)
          Process the given event.
 void onReplayFailed(Throwable cause)
          Invoked when a replay has failed due to an exception.
 void subscribe()
          Deprecated. Use EventBus.subscribe(org.axonframework.eventhandling.EventListener) and pass this adapter instance to subscribe it.
static AnnotationEventListenerAdapter subscribe(Object annotatedEventListener, EventBus eventBus)
          Subscribe the given annotatedEventListener to the given eventBus.
 void unsubscribe()
          Deprecated. Use EventBus.unsubscribe(org.axonframework.eventhandling.EventListener) and pass this adapter instance to unsubscribe it.
 
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)
Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus.

Parameters:
annotatedEventListener - the annotated event listener

AnnotationEventListenerAdapter

public AnnotationEventListenerAdapter(Object annotatedEventListener,
                                      ParameterResolverFactory parameterResolverFactory)
Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus. The given parameterResolverFactory is used to resolve parameter values for handler methods.

Parameters:
annotatedEventListener - the annotated event listener
parameterResolverFactory - the strategy for resolving handler method parameter values

AnnotationEventListenerAdapter

@Deprecated
public AnnotationEventListenerAdapter(Object annotatedEventListener,
                                                 EventBus eventBus)
Deprecated. Use AnnotationEventListenerAdapter(Object) and subscribe the listener to the event bus using EventBus.subscribe(org.axonframework.eventhandling.EventListener)

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
@Deprecated
public void unsubscribe()
Deprecated. Use EventBus.unsubscribe(org.axonframework.eventhandling.EventListener) and pass this adapter instance to unsubscribe it.

Unsubscribe the EventListener with the configured EventBus.

Specified by:
unsubscribe in interface Subscribable

subscribe

@PostConstruct
@Deprecated
public void subscribe()
Deprecated. Use EventBus.subscribe(org.axonframework.eventhandling.EventListener) and pass this adapter instance to subscribe it.

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

beforeReplay

public void beforeReplay()
Description copied from interface: ReplayAware
Invoked when a replay is started.

Specified by:
beforeReplay in interface ReplayAware

afterReplay

public void afterReplay()
Description copied from interface: ReplayAware
Invoked when a replay has finished.

Specified by:
afterReplay in interface ReplayAware

onReplayFailed

public void onReplayFailed(Throwable cause)
Description copied from interface: ReplayAware
Invoked when a replay has failed due to an exception.

Specified by:
onReplayFailed in interface ReplayAware
Parameters:
cause - The exception that stopped the replay;


Copyright © 2010-2016. All Rights Reserved.