class DisposableBeanAdapter extends java.lang.Object implements DisposableBean, java.lang.Runnable, java.io.Serializable
DisposableBean
and Runnable
interfaces performing various destruction steps on a given bean instance:
AbstractBeanFactory
,
DisposableBean
,
DestructionAwareBeanPostProcessor
,
AbstractBeanDefinition.getDestroyMethodName()
Modifier and Type | Field and Description |
---|---|
private java.security.AccessControlContext |
acc |
private java.lang.Object |
bean |
private java.lang.String |
beanName |
private java.util.List<DestructionAwareBeanPostProcessor> |
beanPostProcessors |
private static java.lang.String |
CLOSE_METHOD_NAME |
private java.lang.reflect.Method |
destroyMethod |
private java.lang.String |
destroyMethodName |
private boolean |
invokeDisposableBean |
private static Log |
logger |
private boolean |
nonPublicAccessAllowed |
private static java.lang.String |
SHUTDOWN_METHOD_NAME |
Modifier | Constructor and Description |
---|---|
|
DisposableBeanAdapter(java.lang.Object bean,
java.util.List<BeanPostProcessor> postProcessors,
java.security.AccessControlContext acc)
Create a new DisposableBeanAdapter for the given bean.
|
private |
DisposableBeanAdapter(java.lang.Object bean,
java.lang.String beanName,
boolean invokeDisposableBean,
boolean nonPublicAccessAllowed,
java.lang.String destroyMethodName,
java.util.List<DestructionAwareBeanPostProcessor> postProcessors)
Create a new DisposableBeanAdapter for the given bean.
|
|
DisposableBeanAdapter(java.lang.Object bean,
java.lang.String beanName,
RootBeanDefinition beanDefinition,
java.util.List<BeanPostProcessor> postProcessors,
java.security.AccessControlContext acc)
Create a new DisposableBeanAdapter for the given bean.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Invoked by a BeanFactory on destruction of a singleton.
|
private java.lang.reflect.Method |
determineDestroyMethod() |
private java.util.List<DestructionAwareBeanPostProcessor> |
filterPostProcessors(java.util.List<BeanPostProcessor> processors,
java.lang.Object bean)
Search for all DestructionAwareBeanPostProcessors in the List.
|
private java.lang.reflect.Method |
findDestroyMethod() |
static boolean |
hasApplicableProcessors(java.lang.Object bean,
java.util.List<BeanPostProcessor> postProcessors)
Check whether the given bean has destruction-aware post-processors applying to it.
|
static boolean |
hasDestroyMethod(java.lang.Object bean,
RootBeanDefinition beanDefinition)
Check whether the given bean has any kind of destroy method to call.
|
private java.lang.String |
inferDestroyMethodIfNecessary(java.lang.Object bean,
RootBeanDefinition beanDefinition)
If the current value of the given beanDefinition's "destroyMethodName" property is
AbstractBeanDefinition.INFER_METHOD , then attempt to infer a destroy method. |
private void |
invokeCustomDestroyMethod(java.lang.reflect.Method destroyMethod)
Invoke the specified custom destroy method on the given bean.
|
void |
run() |
protected java.lang.Object |
writeReplace()
Serializes a copy of the state of this class,
filtering out non-serializable BeanPostProcessors.
|
private static final java.lang.String CLOSE_METHOD_NAME
private static final java.lang.String SHUTDOWN_METHOD_NAME
private static final Log logger
private final java.lang.Object bean
private final java.lang.String beanName
private final boolean invokeDisposableBean
private final boolean nonPublicAccessAllowed
private final java.security.AccessControlContext acc
private java.lang.String destroyMethodName
private transient java.lang.reflect.Method destroyMethod
private java.util.List<DestructionAwareBeanPostProcessor> beanPostProcessors
public DisposableBeanAdapter(java.lang.Object bean, java.lang.String beanName, RootBeanDefinition beanDefinition, java.util.List<BeanPostProcessor> postProcessors, java.security.AccessControlContext acc)
bean
- the bean instance (never null
)beanName
- the name of the beanbeanDefinition
- the merged bean definitionpostProcessors
- the List of BeanPostProcessors
(potentially DestructionAwareBeanPostProcessor), if anypublic DisposableBeanAdapter(java.lang.Object bean, java.util.List<BeanPostProcessor> postProcessors, java.security.AccessControlContext acc)
bean
- the bean instance (never null
)postProcessors
- the List of BeanPostProcessors
(potentially DestructionAwareBeanPostProcessor), if anyprivate DisposableBeanAdapter(java.lang.Object bean, java.lang.String beanName, boolean invokeDisposableBean, boolean nonPublicAccessAllowed, java.lang.String destroyMethodName, java.util.List<DestructionAwareBeanPostProcessor> postProcessors)
private java.lang.String inferDestroyMethodIfNecessary(java.lang.Object bean, RootBeanDefinition beanDefinition)
AbstractBeanDefinition.INFER_METHOD
, then attempt to infer a destroy method.
Candidate methods are currently limited to public, no-arg methods named "close" or
"shutdown" (whether declared locally or inherited). The given BeanDefinition's
"destroyMethodName" is updated to be null if no such method is found, otherwise set
to the name of the inferred method. This constant serves as the default for the
@Bean#destroyMethod
attribute and the value of the constant may also be
used in XML within the <bean destroy-method="">
or <beans default-destroy-method="">
attributes.
Also processes the Closeable
and AutoCloseable
interfaces, reflectively calling the "close" method on implementing beans as well.
private java.util.List<DestructionAwareBeanPostProcessor> filterPostProcessors(java.util.List<BeanPostProcessor> processors, java.lang.Object bean)
processors
- the List to searchpublic void run()
run
in interface java.lang.Runnable
public void destroy()
DisposableBean
destroy
in interface DisposableBean
private java.lang.reflect.Method determineDestroyMethod()
private java.lang.reflect.Method findDestroyMethod()
private void invokeCustomDestroyMethod(java.lang.reflect.Method destroyMethod)
This implementation invokes a no-arg method if found, else checking for a method with a single boolean argument (passing in "true", assuming a "force" parameter), else logging an error.
protected java.lang.Object writeReplace()
public static boolean hasDestroyMethod(java.lang.Object bean, RootBeanDefinition beanDefinition)
bean
- the bean instancebeanDefinition
- the corresponding bean definitionpublic static boolean hasApplicableProcessors(java.lang.Object bean, java.util.List<BeanPostProcessor> postProcessors)
bean
- the bean instancepostProcessors
- the post-processor candidates