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 java.lang.reflect.Method |
destroyMethod |
private java.lang.String |
destroyMethodName |
private boolean |
invokeDisposableBean |
private static Log |
logger |
private boolean |
nonPublicAccessAllowed |
Modifier | Constructor and Description |
---|---|
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> postProcessors)
Search for all DestructionAwareBeanPostProcessors in the List.
|
private java.lang.reflect.Method |
findDestroyMethod() |
private void |
inferDestroyMethodIfNecessary(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 Log logger
private final java.lang.Object bean
private final java.lang.String beanName
private final boolean invokeDisposableBean
private final boolean nonPublicAccessAllowed
private java.lang.String destroyMethodName
private transient java.lang.reflect.Method destroyMethod
private java.util.List<DestructionAwareBeanPostProcessor> beanPostProcessors
private final java.security.AccessControlContext acc
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 anyprivate DisposableBeanAdapter(java.lang.Object bean, java.lang.String beanName, boolean invokeDisposableBean, boolean nonPublicAccessAllowed, java.lang.String destroyMethodName, java.util.List<DestructionAwareBeanPostProcessor> postProcessors)
private void inferDestroyMethodIfNecessary(RootBeanDefinition beanDefinition)
AbstractBeanDefinition.INFER_METHOD
, then attempt to infer a destroy method.
Candidate methods are currently limited to public, no-arg methods named 'close'
(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.private java.util.List<DestructionAwareBeanPostProcessor> filterPostProcessors(java.util.List<BeanPostProcessor> postProcessors)
postProcessors
- 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()