Top Description Inners Fields Constructors Methods
org.springframework.beans.factory.support

pack-priv Class DisposableBeanAdapter

extends Object
implements DisposableBean, Runnable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Runnable, org.springframework.beans.factory.DisposableBean
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.lang.reflect.InvocationTargetException, .Method, java.util.ArrayList, .List, java.util.concurrent.CountDownLatch, .ExecutionException, .Future, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Subscriber, .Subscription, org.springframework.beans.BeanUtils, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, org.springframework.core.ReactiveAdapter, .ReactiveAdapterRegistry, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, .ObjectUtils, .ReflectionUtils, .StringUtils

Adapter that implements the DisposableBean and Runnable interfaces performing various destruction steps on a given bean instance:
Authors
Juergen Hoeller, Costin Leau, Stephane Nicoll, Sam Brannen, Sebastien Deleuze
Since
2.0
See Also
AbstractBeanFactory, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor, AbstractBeanDefinition#getDestroyMethodNames()

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
DisposableBeanAdapter.DestroyMethodSubscriber

Reactive Streams Subscriber for destroy method completion.

private class
DisposableBeanAdapter.ReactiveDestroyMethodHandler

Inner class to avoid a hard dependency on the Reactive Streams API at runtime.

Field Summary

Modifier and TypeField and Description
private final Object
private final String
private final List<DestructionAwareBeanPostProcessor>
private static final String
private static final String
private String[]
private transient Method[]
private boolean
private final boolean
private static final Log
private final boolean
private static final boolean
private static final String

Constructor Summary

AccessConstructor and Description
public
DisposableBeanAdapter(Object
the bean instance (never null)
bean
,
String
the name of the bean
beanName
,
RootBeanDefinition
the merged bean definition
beanDefinition
,
List<DestructionAwareBeanPostProcessor>
the List of BeanPostProcessors (potentially DestructionAwareBeanPostProcessor), if any
postProcessors
)

Create a new DisposableBeanAdapter for the given bean.

public
DisposableBeanAdapter(Object
the bean instance (never null)
bean
,
List<DestructionAwareBeanPostProcessor>
the List of BeanPostProcessors (potentially DestructionAwareBeanPostProcessor), if any
postProcessors
)

Create a new DisposableBeanAdapter for the given bean.

private
DisposableBeanAdapter(Object bean, String beanName, boolean nonPublicAccessAllowed, boolean invokeDisposableBean, boolean invokeAutoCloseable, String[] destroyMethodNames, List<DestructionAwareBeanPostProcessor> postProcessors)

Create a new DisposableBeanAdapter for the given bean.

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.

private Method
determineDestroyMethod(String destroyMethodName)

private static List<DestructionAwareBeanPostProcessor>

Returns:

the filtered List of DestructionAwareBeanPostProcessors
filterPostProcessors
(List<DestructionAwareBeanPostProcessor>
the List to search
processors
,
Object bean)

Search for all DestructionAwareBeanPostProcessors in the List.

private Method
findDestroyMethod(Class<?> clazz, String name)

public static boolean
hasApplicableProcessors(Object
the bean instance
bean
,
List<DestructionAwareBeanPostProcessor>
the post-processor candidates
postProcessors
)

Check whether the given bean has destruction-aware post-processors applying to it.

public static boolean
hasDestroyMethod(Object
the bean instance
bean
,
RootBeanDefinition
the corresponding bean definition
beanDefinition
)

Check whether the given bean has any kind of destroy method to call.

pack-priv static String[]
inferDestroyMethodsIfNecessary(Class<?> target, 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(Method destroyMethod)

Invoke the specified custom destroy method on the given bean.

pack-priv void
logDestroyMethodCompletion(Method destroyMethod, boolean async)

pack-priv void
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

protected Object
writeReplace()

Serializes a copy of the state of this class, filtering out non-serializable BeanPostProcessors.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanback to summary
private final Object bean
beanNameback to summary
private final String beanName
beanPostProcessorsback to summary
private final List<DestructionAwareBeanPostProcessor> beanPostProcessors
Annotations
@Nullable
CLOSE_METHOD_NAMEback to summary
private static final String CLOSE_METHOD_NAME
DESTROY_METHOD_NAMEback to summary
private static final String DESTROY_METHOD_NAME
destroyMethodNamesback to summary
private String[] destroyMethodNames
Annotations
@Nullable
destroyMethodsback to summary
private transient Method[] destroyMethods
Annotations
@Nullable
invokeAutoCloseableback to summary
private boolean invokeAutoCloseable
invokeDisposableBeanback to summary
private final boolean invokeDisposableBean
loggerback to summary
private static final Log logger
nonPublicAccessAllowedback to summary
private final boolean nonPublicAccessAllowed
reactiveStreamsPresentback to summary
private static final boolean reactiveStreamsPresent
SHUTDOWN_METHOD_NAMEback to summary
private static final String SHUTDOWN_METHOD_NAME

Constructor Detail

DisposableBeanAdapterback to summary
public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition, List<DestructionAwareBeanPostProcessor> postProcessors)

Create a new DisposableBeanAdapter for the given bean.

Parameters
bean:Object

the bean instance (never null)

beanName:String

the name of the bean

beanDefinition:RootBeanDefinition

the merged bean definition

postProcessors:List<DestructionAwareBeanPostProcessor>

the List of BeanPostProcessors (potentially DestructionAwareBeanPostProcessor), if any

DisposableBeanAdapterback to summary
public DisposableBeanAdapter(Object bean, List<DestructionAwareBeanPostProcessor> postProcessors)

Create a new DisposableBeanAdapter for the given bean.

Parameters
bean:Object

the bean instance (never null)

postProcessors:List<DestructionAwareBeanPostProcessor>

the List of BeanPostProcessors (potentially DestructionAwareBeanPostProcessor), if any

DisposableBeanAdapterback to summary
private DisposableBeanAdapter(Object bean, String beanName, boolean nonPublicAccessAllowed, boolean invokeDisposableBean, boolean invokeAutoCloseable, String[] destroyMethodNames, List<DestructionAwareBeanPostProcessor> postProcessors)

Create a new DisposableBeanAdapter for the given bean.

Method Detail

destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Doc from org.springframework.beans.factory.DisposableBean.destroy.

Invoked by the containing BeanFactory on destruction of a bean.

Annotations
@Override
determineDestroyMethodback to summary
private Method determineDestroyMethod(String destroyMethodName)
Annotations
@Nullable
filterPostProcessorsback to summary
private static List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<DestructionAwareBeanPostProcessor> processors, Object bean)

Search for all DestructionAwareBeanPostProcessors in the List.

Parameters
processors:List<DestructionAwareBeanPostProcessor>

the List to search

Returns:List<DestructionAwareBeanPostProcessor>

the filtered List of DestructionAwareBeanPostProcessors

Annotations
@Nullable
findDestroyMethodback to summary
private Method findDestroyMethod(Class<?> clazz, String name)
Annotations
@Nullable
hasApplicableProcessorsback to summary
public static boolean hasApplicableProcessors(Object bean, List<DestructionAwareBeanPostProcessor> postProcessors)

Check whether the given bean has destruction-aware post-processors applying to it.

Parameters
bean:Object

the bean instance

postProcessors:List<DestructionAwareBeanPostProcessor>

the post-processor candidates

hasDestroyMethodback to summary
public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefinition)

Check whether the given bean has any kind of destroy method to call.

Parameters
bean:Object

the bean instance

beanDefinition:RootBeanDefinition

the corresponding bean definition

inferDestroyMethodsIfNecessaryback to summary
pack-priv static String[] inferDestroyMethodsIfNecessary(Class<?> target, RootBeanDefinition beanDefinition)

If the current value of the given beanDefinition's "destroyMethodName" property is 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 java.io.Closeable and java.lang.AutoCloseable interfaces, reflectively calling the "close" method on implementing beans as well.

Annotations
@Nullable
invokeCustomDestroyMethodback to summary
private void invokeCustomDestroyMethod(Method destroyMethod)

Invoke the specified custom destroy method on the given bean.

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.

logDestroyMethodCompletionback to summary
pack-priv void logDestroyMethodCompletion(Method destroyMethod, boolean async)
logDestroyMethodExceptionback to summary
pack-priv void logDestroyMethodException(Method destroyMethod, Throwable ex)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
writeReplaceback to summary
protected Object writeReplace()

Serializes a copy of the state of this class, filtering out non-serializable BeanPostProcessors.

org.springframework.beans.factory.support back to summary

private Class DisposableBeanAdapter.DestroyMethodSubscriber

extends Object
implements Subscriber<Object>
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.support.DisposableBeanAdapter.DestroyMethodSubscriber
All Implemented Interfaces
org.reactivestreams.Subscriber

Reactive Streams Subscriber for destroy method completion.

Field Summary

Modifier and TypeField and Description
private final Method
private final CountDownLatch

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

public void
onError(Throwable
the throwable signaled
t
)

Implements org.reactivestreams.Subscriber.onError.

Failed terminal state.

public void
onNext(Object
the element signaled
o
)

Implements org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

destroyMethodback to summary
private final Method destroyMethod
latchback to summary
private final CountDownLatch latch

Constructor Detail

DestroyMethodSubscriberback to summary
public DestroyMethodSubscriber(Method destroyMethod, CountDownLatch latch)

Method Detail

onCompleteback to summary
public void onComplete()

Implements org.reactivestreams.Subscriber.onComplete.

Doc from org.reactivestreams.Subscriber.onComplete.

Successful terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Annotations
@Override
onErrorback to summary
public void onError(Throwable t)

Implements org.reactivestreams.Subscriber.onError.

Doc from org.reactivestreams.Subscriber.onError.

Failed terminal state.

No further events will be sent even if Subscription#request(long) is invoked again.

Parameters
t:Throwable

the throwable signaled

Annotations
@Override
onNextback to summary
public void onNext(Object o)

Implements org.reactivestreams.Subscriber.onNext.

Doc from org.reactivestreams.Subscriber.onNext.

Data notification sent by the Publisher in response to requests to Subscription#request(long).

Parameters
o:Object

the element signaled

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Subscription s)

Implements org.reactivestreams.Subscriber.onSubscribe.

Doc from org.reactivestreams.Subscriber.onSubscribe.

Invoked after calling Publisher#subscribe(Subscriber).

No data will start flowing until Subscription#request(long) is invoked.

It is the responsibility of this Subscriber instance to call Subscription#request(long) whenever more data is wanted.

The Publisher will send notifications only in response to Subscription#request(long).

Parameters
s:Subscription

the Subscription that allows requesting data via Subscription#request(long)

Annotations
@Override
org.springframework.beans.factory.support back to summary

private Class DisposableBeanAdapter.ReactiveDestroyMethodHandler

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.beans.factory.support.DisposableBeanAdapter.ReactiveDestroyMethodHandler

Inner class to avoid a hard dependency on the Reactive Streams API at runtime.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
await(Method destroyMethod, Object returnValue)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ReactiveDestroyMethodHandlerback to summary
private ReactiveDestroyMethodHandler()

Method Detail

awaitback to summary
public boolean await(Method destroyMethod, Object returnValue) throws InterruptedException