本文整理汇总了Java中org.springframework.beans.factory.DisposableBean类的典型用法代码示例。如果您正苦于以下问题:Java DisposableBean类的具体用法?Java DisposableBean怎么用?Java DisposableBean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DisposableBean类属于org.springframework.beans.factory包,在下文中一共展示了DisposableBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ManagedFactoryDisposableInvoker
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* Constructs a new <code>ManagedFactoryDisposableAdapter</code> instance.
*
* @param methodName destruction method name
*/
public ManagedFactoryDisposableInvoker(Class<?> beanClass, String methodName) {
this.isDisposable = DisposableBean.class.isAssignableFrom(beanClass);
if (StringUtils.hasText(methodName)) {
this.customSpringMethod = detectCustomSpringMethod(beanClass, methodName);
if (customSpringMethod != null) {
Class<?>[] types = customSpringMethod.getParameterTypes();
this.customSpringMethodArgs = ((types.length == 1 && types[0].equals(boolean.class)) ? new Object[] { Boolean.TRUE }
: null);
}
else {
this.customSpringMethodArgs = null;
}
this.customOsgiDestructionMethod = detectCustomOsgiMethod(beanClass, methodName);
}
else {
this.customSpringMethod = null;
this.customSpringMethodArgs = null;
this.customOsgiDestructionMethod = null;
}
}
示例2: destroy
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
public void destroy(String beanName, Object beanInstance, DestructionCodes code) {
// first invoke disposable bean
if (isDisposable) {
if (log.isDebugEnabled()) {
log.debug("Invoking destroy() on bean with name '" + beanName + "'");
}
try {
((DisposableBean) beanInstance).destroy();
}
catch (Throwable ex) {
String msg = "Invocation of destroy method failed on bean with name '" + beanName + "'";
if (log.isDebugEnabled()) {
log.warn(msg, ex);
}
else {
log.warn(msg + ": " + ex);
}
}
}
// custom callback (no argument)
invokeCustomMethod(beanName, beanInstance);
// custom callback (int argument)
invokeCustomMethod(beanName, beanInstance, code);
}
示例3: testAppContextClassHierarchy
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
public void testAppContextClassHierarchy() {
Class<?>[] clazz =
ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);
//Closeable.class,
Class<?>[] expected =
new Class<?>[] { OsgiBundleXmlApplicationContext.class,
AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
DefaultResourceLoader.class, ResourceLoader.class,
AutoCloseable.class,
DelegatedExecutionOsgiBundleApplicationContext.class,
ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
MessageSource.class, BeanFactory.class, DisposableBean.class };
assertTrue(compareArrays(expected, clazz));
}
示例4: cleanupAttributes
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* Find all ServletContext attributes which implement {@link DisposableBean}
* and destroy them, removing all affected ServletContext attributes eventually.
* @param sc the ServletContext to check
*/
static void cleanupAttributes(ServletContext sc) {
Enumeration<String> attrNames = sc.getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = attrNames.nextElement();
if (attrName.startsWith("org.springframework.")) {
Object attrValue = sc.getAttribute(attrName);
if (attrValue instanceof DisposableBean) {
try {
((DisposableBean) attrValue).destroy();
}
catch (Throwable ex) {
logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex);
}
}
}
}
}
示例5: inferDestroyMethodIfNecessary
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* If the current value of the given beanDefinition's "destroyMethodName" property is
* {@link 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
* {@code @Bean#destroyMethod} attribute and the value of the constant may also be
* used in XML within the {@code <bean destroy-method="">} or {@code
* <beans default-destroy-method="">} attributes.
* <p>Also processes the {@link java.io.Closeable} and {@link java.lang.AutoCloseable}
* interfaces, reflectively calling the "close" method on implementing beans as well.
*/
private String inferDestroyMethodIfNecessary(Object bean, RootBeanDefinition beanDefinition) {
if (AbstractBeanDefinition.INFER_METHOD.equals(beanDefinition.getDestroyMethodName()) ||
(beanDefinition.getDestroyMethodName() == null && closeableInterface.isInstance(bean))) {
// Only perform destroy method inference or Closeable detection
// in case of the bean not explicitly implementing DisposableBean
if (!(bean instanceof DisposableBean)) {
try {
return bean.getClass().getMethod(CLOSE_METHOD_NAME).getName();
}
catch (NoSuchMethodException ex) {
try {
return bean.getClass().getMethod(SHUTDOWN_METHOD_NAME).getName();
}
catch (NoSuchMethodException ex2) {
// no candidate destroy method found
}
}
}
return null;
}
return beanDefinition.getDestroyMethodName();
}
示例6: destroyPrototypeInstance
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* Subclasses should call this method to destroy an obsolete prototype instance.
* @param target the bean instance to destroy
*/
protected void destroyPrototypeInstance(Object target) {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Destroying instance of bean '" + getTargetBeanName() + "'");
}
if (getBeanFactory() instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) getBeanFactory()).destroyBean(getTargetBeanName(), target);
}
else if (target instanceof DisposableBean) {
try {
((DisposableBean) target).destroy();
}
catch (Throwable ex) {
logger.error("Couldn't invoke destroy method of bean with name '" + getTargetBeanName() + "'", ex);
}
}
}
示例7: inferDestroyMethodIfNecessary
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* If the current value of the given beanDefinition's "destroyMethodName" property is
* {@link 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
* {@code @Bean#destroyMethod} attribute and the value of the constant may also be
* used in XML within the {@code <bean destroy-method="">} or {@code
* <beans default-destroy-method="">} attributes.
* <p>Also processes the {@link java.io.Closeable} and {@link java.lang.AutoCloseable}
* interfaces, reflectively calling the "close" method on implementing beans as well.
*/
private String inferDestroyMethodIfNecessary(Object bean, RootBeanDefinition beanDefinition) {
String destroyMethodName = beanDefinition.getDestroyMethodName();
if (AbstractBeanDefinition.INFER_METHOD.equals(destroyMethodName) ||
(destroyMethodName == null && closeableInterface.isInstance(bean))) {
// Only perform destroy method inference or Closeable detection
// in case of the bean not explicitly implementing DisposableBean
if (!(bean instanceof DisposableBean)) {
try {
return bean.getClass().getMethod(CLOSE_METHOD_NAME).getName();
}
catch (NoSuchMethodException ex) {
try {
return bean.getClass().getMethod(SHUTDOWN_METHOD_NAME).getName();
}
catch (NoSuchMethodException ex2) {
// no candidate destroy method found
}
}
}
return null;
}
return (StringUtils.hasLength(destroyMethodName) ? destroyMethodName : null);
}
示例8: contextDestroyed
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* Close the root web application context.
*/
@Override
public void contextDestroyed(ServletContextEvent event) {
DisambiguationMainService.getInstance().shutDownDisambiguationService();
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event
.getServletContext());
}
ServletContext sc = event.getServletContext();
Enumeration<String> attrNames = sc.getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = attrNames.nextElement();
if (attrName.startsWith("org.springframework.")) {
Object attrValue = sc.getAttribute(attrName);
if (attrValue instanceof DisposableBean) {
try {
((DisposableBean) attrValue).destroy();
} catch (Throwable ex) {
Logger.getRootLogger().fatal(ex.getMessage());
}
}
}
}
}
示例9: close
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* Tries to "close" an object.
* <p>
* This invokes the close method if it is present.
*
* @param obj the object, null ignored
*/
public static void close(final Object obj) {
if (obj != null) {
try {
if (obj instanceof Closeable) {
((Closeable) obj).close();
} else if (obj instanceof Lifecycle) {
((Lifecycle) obj).stop();
} else if (obj instanceof DisposableBean) {
((DisposableBean) obj).destroy();
} else {
invokeNoArgsNoException(obj, "close");
invokeNoArgsNoException(obj, "stop");
invokeNoArgsNoException(obj, "shutdown");
}
} catch (Exception ex) {
// ignored
}
}
}
示例10: waitForTaskExecutorToFinish
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* If an AsyncTaskExecutor is used for loading options/services/transforms, we need to wait for the tasks to complete
* before we e.g. release the DatabaseClient.
*/
public void waitForTaskExecutorToFinish() {
if (shutdownTaskExecutorAfterLoadingModules) {
if (taskExecutor instanceof ExecutorConfigurationSupport) {
((ExecutorConfigurationSupport) taskExecutor).shutdown();
taskExecutor = null;
} else if (taskExecutor instanceof DisposableBean) {
try {
((DisposableBean) taskExecutor).destroy();
} catch (Exception ex) {
logger.warn("Unexpected exception while calling destroy() on taskExecutor: " + ex.getMessage(), ex);
}
taskExecutor = null;
}
} else if (logger.isDebugEnabled()) {
logger.debug("shutdownTaskExecutorAfterLoadingModules is set to false, so not shutting down taskExecutor");
}
}
示例11: onTearDown
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
*/
protected void onTearDown() throws Exception {
if (this.HotBeanModuleRepository1 instanceof AbstractHotBeanModuleRepository) ((AbstractHotBeanModuleRepository) this.HotBeanModuleRepository1)
.destroy();
else if (this.HotBeanModuleRepository1 instanceof DisposableBean)
((DisposableBean) this.HotBeanModuleRepository1).destroy();
if (this.HotBeanModuleRepository2 instanceof AbstractHotBeanModuleRepository) ((AbstractHotBeanModuleRepository) this.HotBeanModuleRepository2)
.destroy();
else if (this.HotBeanModuleRepository2 instanceof DisposableBean)
((DisposableBean) this.HotBeanModuleRepository2).destroy();
logger.info("Cleaning up files.");
// Clean up
// FileDeletor.deleteTreeImpl("test/junit/hotModules");
logger.info("Clean up complete.");
}
示例12: cleanupAttributes
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
/**
* Find all ServletContext attributes which implement {@link DisposableBean}
* and destroy them, removing all affected ServletContext attributes eventually.
* @param sc the ServletContext to check
*/
static void cleanupAttributes(ServletContext sc) {
Enumeration attrNames = sc.getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = (String) attrNames.nextElement();
if (attrName.startsWith("org.springframework.")) {
Object attrValue = sc.getAttribute(attrName);
if (attrValue instanceof DisposableBean) {
try {
((DisposableBean) attrValue).destroy();
}
catch (Throwable ex) {
logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex);
}
}
}
}
}
示例13: createCache_withMockedRedisConnectionFactory_createsAndDestroysConnectionFactory
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
@Test
public void createCache_withMockedRedisConnectionFactory_createsAndDestroysConnectionFactory() throws Exception {
//Arrange
RedisConnectionFactory connectionFactory = Mockito.mock(RedisConnectionFactory.class, Mockito.withSettings().extraInterfaces(DisposableBean.class));
RedisCacheFactory redisCacheFactory = new RedisCacheFactory() {
@Override
protected RedisConnectionFactory createConnectionClient(String hostName, int port) {
assertEquals("someHost", hostName);
assertEquals(4711, port);
return connectionFactory;
}
};
//Act
Cache cache = redisCacheFactory.createCache("test", "someHost", 4711);
redisCacheFactory.destroy();
//Assert
assertNotNull(cache);
assertEquals("test", cache.getName());
assertNotNull(cache.getNativeCache());
DisposableBean disposableBean = (DisposableBean) connectionFactory;
Mockito.verify(disposableBean, Mockito.times(1)).destroy();
}
示例14: testAppContextClassHierarchy
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
public void testAppContextClassHierarchy() {
Class[] clazz = ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class,
ClassUtils.INCLUDE_ALL_CLASSES);
Class[] expected = new Class[] { OsgiBundleXmlApplicationContext.class,
AbstractDelegatedExecutionApplicationContext.class, DelegatedExecutionOsgiBundleApplicationContext.class,
ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class, ApplicationContext.class,
Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
HierarchicalBeanFactory.class, MessageSource.class, ApplicationEventPublisher.class,
ResourcePatternResolver.class, BeanFactory.class, ResourceLoader.class, AutoCloseable.class,
AbstractOsgiBundleApplicationContext.class, AbstractRefreshableApplicationContext.class,
AbstractApplicationContext.class, DisposableBean.class, DefaultResourceLoader.class };
String msg = "Class: ";
for (int i=0;i<clazz.length;i++) {
msg += clazz[i].getSimpleName() + " ";
}
assertTrue(msg, compareArrays(expected, clazz));
}
示例15: destroy
import org.springframework.beans.factory.DisposableBean; //导入依赖的package包/类
@Override
public void destroy() throws Exception {
if (executor instanceof DisposableBean) {
DisposableBean bean = (DisposableBean) executor;
bean.destroy();
}
}