org.axonframework.common.annotation
Class AbstractAnnotationHandlerBeanPostProcessor<I,T extends I>

java.lang.Object
  extended by org.axonframework.common.annotation.AbstractAnnotationHandlerBeanPostProcessor<I,T>
Type Parameters:
I - The primary interface of the adapter being created
T - The type of adapter created by this class
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
Direct Known Subclasses:
AnnotationCommandHandlerBeanPostProcessor, AnnotationEventListenerBeanPostProcessor

public abstract class AbstractAnnotationHandlerBeanPostProcessor<I,T extends I>
extends Object
implements org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, org.springframework.context.ApplicationContextAware, org.springframework.context.SmartLifecycle

Abstract bean post processor that finds candidates for proxying. Typically used to wrap annotated beans with their respective interface implementations.

Since:
0.4
Author:
Allard Buijze

Constructor Summary
AbstractAnnotationHandlerBeanPostProcessor()
           
 
Method Summary
protected abstract  Class<I> getAdapterInterface()
          Returns the interface that the adapter implements to connect the annotated method to the actual interface definition.
protected  org.springframework.context.ApplicationContext getApplicationContext()
          Returns the ApplicationContext this Bean Post Processor is registered in.
 int getPhase()
           
protected abstract  T initializeAdapterFor(Object bean, ParameterResolverFactory parameterResolverFactory)
          Create an AnnotationEventListenerAdapter instance of the given bean.
 boolean isAutoStartup()
           
protected abstract  boolean isPostProcessingCandidate(Class<?> targetClass)
          Indicates whether an object of the given targetClass should be post processed.
 boolean isRunning()
           
 Object postProcessAfterInitialization(Object bean, String beanName)
          
 void postProcessBeforeDestruction(Object bean, String beanName)
          
 Object postProcessBeforeInitialization(Object bean, String beanName)
          
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          
 void setParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
          Sets the ParameterResolverFactory to create the Parameter Resolvers with that provide the parameter values for the handler methods.
 void setPhase(int phase)
          Sets the phase in which handlers are subscribed and unsubscribed.
 void setUnsubscribeOnShutdown(boolean unsubscribeOnShutdown)
          Indicates whether handlers should be unsubscribed on shutdown.
 void start()
           
 void stop()
           
 void stop(Runnable callback)
           
protected abstract  void subscribe(I bean, T adapter)
          Subscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.
protected abstract  void unsubscribe(I bean, T adapter)
          Unsubscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAnnotationHandlerBeanPostProcessor

public AbstractAnnotationHandlerBeanPostProcessor()
Method Detail

postProcessBeforeInitialization

public Object postProcessBeforeInitialization(Object bean,
                                              String beanName)
                                       throws org.springframework.beans.BeansException

Specified by:
postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
Throws:
org.springframework.beans.BeansException

postProcessAfterInitialization

public Object postProcessAfterInitialization(Object bean,
                                             String beanName)
                                      throws org.springframework.beans.BeansException

Specified by:
postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
Throws:
org.springframework.beans.BeansException

getAdapterInterface

protected abstract Class<I> getAdapterInterface()
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.

Returns:
the interface that the adapter implements to connect the annotated method to the actual interface definition

isPostProcessingCandidate

protected abstract boolean isPostProcessingCandidate(Class<?> targetClass)
Indicates whether an object of the given targetClass should be post processed.

Parameters:
targetClass - The type of bean
Returns:
true to post process bean of given type, false otherwise

isAutoStartup

public boolean isAutoStartup()
Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

stop

public void stop(Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle

start

public void start()
Specified by:
start in interface org.springframework.context.Lifecycle

stop

public void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

isRunning

public boolean isRunning()
Specified by:
isRunning in interface org.springframework.context.Lifecycle

getPhase

public int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased

setPhase

public void setPhase(int phase)
Sets the phase in which handlers are subscribed and unsubscribed. Defaults to 0.

Parameters:
phase - The phase in which handlers are subscribed and unsubscribed

postProcessBeforeDestruction

public void postProcessBeforeDestruction(Object bean,
                                         String beanName)
                                  throws org.springframework.beans.BeansException

Specified by:
postProcessBeforeDestruction in interface org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
Throws:
org.springframework.beans.BeansException

subscribe

protected abstract void subscribe(I bean,
                                  T adapter)
Subscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.

Parameters:
bean - The bean to subscribe
adapter - The adapter wrapping the bean

unsubscribe

protected abstract void unsubscribe(I bean,
                                    T adapter)
Unsubscribe the given proxy bean (with its annotated methods managed by given adapter) to the messaging infrastructure.

Parameters:
bean - The bean to unsubscribe
adapter - The adapter wrapping the bean

initializeAdapterFor

protected abstract T initializeAdapterFor(Object bean,
                                          ParameterResolverFactory parameterResolverFactory)
Create an AnnotationEventListenerAdapter instance of the given bean. This adapter will receive all event handler calls to be handled by this bean.

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

getApplicationContext

protected org.springframework.context.ApplicationContext getApplicationContext()
Returns the ApplicationContext this Bean Post Processor is registered in.

Returns:
the ApplicationContext this Bean Post Processor is registered in

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

setUnsubscribeOnShutdown

public void setUnsubscribeOnShutdown(boolean unsubscribeOnShutdown)
Indicates whether handlers should be unsubscribed on shutdown. Defaults to true.

Parameters:
unsubscribeOnShutdown - true to unsubscribe beans explicitly from their command/event bus or false to shutdown without unsubscribing explicitly.

setParameterResolverFactory

public void setParameterResolverFactory(ParameterResolverFactory parameterResolverFactory)
Sets the ParameterResolverFactory to create the Parameter Resolvers with that provide the parameter values for the handler methods.

Parameters:
parameterResolverFactory - The parameter resolver factory to resolve parameter values with


Copyright © 2010-2016. All Rights Reserved.