org.axonframework.eventhandling.annotation
Class AnnotationEventListenerBeanPostProcessor

java.lang.Object
  extended by org.axonframework.common.annotation.AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
      extended by org.axonframework.eventhandling.annotation.AnnotationEventListenerBeanPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class AnnotationEventListenerBeanPostProcessor
extends AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
implements org.springframework.context.SmartLifecycle

Spring Bean post processor that automatically generates an adapter for each bean containing EventHandler annotated methods.

Since:
0.3
Author:
Allard Buijze

Constructor Summary
AnnotationEventListenerBeanPostProcessor()
           
 
Method Summary
protected  Class<EventListener> getAdapterInterface()
          Returns the interface that the adapter implements to connect the annotated method to the actual interface definition.
protected  AnnotationEventListenerAdapter initializeAdapterFor(Object bean, ParameterResolverFactory parameterResolverFactory)
          Create an AnnotationEventListenerAdapter instance of the given bean.
protected  boolean isPostProcessingCandidate(Class<?> targetClass)
          Indicates whether an object of the given targetClass should be post processed.
 void setEventBus(EventBus eventBus)
          Sets the event bus to which detected event listeners should be subscribed.
protected  void subscribe(EventListener bean, AnnotationEventListenerAdapter adapter)
          Subscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.
protected  void unsubscribe(EventListener bean, AnnotationEventListenerAdapter adapter)
          Unsubscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.
 
Methods inherited from class org.axonframework.common.annotation.AbstractAnnotationHandlerBeanPostProcessor
getApplicationContext, getPhase, isAutoStartup, isRunning, postProcessAfterInitialization, postProcessBeforeDestruction, postProcessBeforeInitialization, setApplicationContext, setParameterResolverFactory, setPhase, setUnsubscribeOnShutdown, start, stop, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, stop
 
Methods inherited from interface org.springframework.context.Lifecycle
isRunning, start, stop
 
Methods inherited from interface org.springframework.context.Phased
getPhase
 

Constructor Detail

AnnotationEventListenerBeanPostProcessor

public AnnotationEventListenerBeanPostProcessor()
Method Detail

getAdapterInterface

protected Class<EventListener> getAdapterInterface()
Description copied from class: AbstractAnnotationHandlerBeanPostProcessor
Returns the interface that the adapter implements to connect the annotated method to the actual interface definition. Calls to methods declared on this interface are passed to the adapter, while other method calls will be forwarded to the annotated object itself.

Note: this *must* be an interface. It may not be an (abstract) class.

Specified by:
getAdapterInterface in class AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
Returns:
the interface that the adapter implements to connect the annotated method to the actual interface definition

initializeAdapterFor

protected AnnotationEventListenerAdapter initializeAdapterFor(Object bean,
                                                              ParameterResolverFactory parameterResolverFactory)
Description copied from class: AbstractAnnotationHandlerBeanPostProcessor
Create an AnnotationEventListenerAdapter instance of the given bean. This adapter will receive all event handler calls to be handled by this bean.

Specified by:
initializeAdapterFor in class AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
Parameters:
bean - The bean that the EventListenerAdapter has to adapt
parameterResolverFactory - The parameter resolver factory that provides the parameter resolvers for the annotated handlers
Returns:
an event handler adapter for the given bean

isPostProcessingCandidate

protected boolean isPostProcessingCandidate(Class<?> targetClass)
Description copied from class: AbstractAnnotationHandlerBeanPostProcessor
Indicates whether an object of the given targetClass should be post processed.

Specified by:
isPostProcessingCandidate in class AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
Parameters:
targetClass - The type of bean
Returns:
true to post process bean of given type, false otherwise

subscribe

protected void subscribe(EventListener bean,
                         AnnotationEventListenerAdapter adapter)
Description copied from class: AbstractAnnotationHandlerBeanPostProcessor
Subscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.

Specified by:
subscribe in class AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
Parameters:
bean - The bean to subscribe
adapter - The adapter wrapping the bean

unsubscribe

protected void unsubscribe(EventListener bean,
                           AnnotationEventListenerAdapter adapter)
Description copied from class: AbstractAnnotationHandlerBeanPostProcessor
Unsubscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.

Specified by:
unsubscribe in class AbstractAnnotationHandlerBeanPostProcessor<EventListener,AnnotationEventListenerAdapter>
Parameters:
bean - The bean to unsubscribe
adapter - The adapter wrapping the bean

setEventBus

public void setEventBus(EventBus eventBus)
Sets the event bus to which detected event listeners should be subscribed. If none is provided, the event bus will be automatically detected in the application context.

Parameters:
eventBus - the event bus to subscribe detected event listeners to


Copyright © 2010-2016. All Rights Reserved.