当前位置: 首页>>代码示例>>Java>>正文


Java DisposableBean类代码示例

本文整理汇总了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;
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:27,代码来源:ManagedFactoryDisposableInvoker.java

示例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);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:27,代码来源:ManagedFactoryDisposableInvoker.java

示例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));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:ClassUtilsTest.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ContextCleanupListener.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:DisposableBeanAdapter.java

示例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);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:AbstractPrototypeBasedTargetSource.java

示例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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:37,代码来源:DisposableBeanAdapter.java

示例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());
				}
			}
		}
	}
}
 
开发者ID:quhfus,项目名称:DoSeR-Disambiguation,代码行数:27,代码来源:FrameworkInitialization.java

示例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
    }
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:ReflectionUtils.java

示例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");
	}
}
 
开发者ID:marklogic-community,项目名称:ml-javaclient-util,代码行数:22,代码来源:DefaultModulesLoader.java

示例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.");
}
 
开发者ID:tolo,项目名称:HotBeans,代码行数:21,代码来源:HotBeanModuleRepositoryTest.java

示例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);
				}
			}
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:23,代码来源:ContextCleanupListener.java

示例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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:27,代码来源:RedisCacheFactoryTest.java

示例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));
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:19,代码来源:ClassUtilsTest.java

示例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();
    }
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:8,代码来源:ExceptionHandlingAsyncTaskExecutor.java


注:本文中的org.springframework.beans.factory.DisposableBean类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。