Search in sources :

Example 1 with DisposableBean

use of org.springframework.beans.factory.DisposableBean in project spring-framework by spring-projects.

the class DefaultSingletonBeanRegistry method destroySingleton.

/**
	 * Destroy the given bean. Delegates to {@code destroyBean}
	 * if a corresponding disposable bean instance is found.
	 * @param beanName the name of the bean
	 * @see #destroyBean
	 */
public void destroySingleton(String beanName) {
    // Remove a registered singleton of the given name, if any.
    removeSingleton(beanName);
    // Destroy the corresponding DisposableBean instance.
    DisposableBean disposableBean;
    synchronized (this.disposableBeans) {
        disposableBean = (DisposableBean) this.disposableBeans.remove(beanName);
    }
    destroyBean(beanName, disposableBean);
}
Also used : DisposableBean(org.springframework.beans.factory.DisposableBean)

Example 2 with DisposableBean

use of org.springframework.beans.factory.DisposableBean in project Settler by EmhyrVarEmreis.

the class ExceptionHandlingAsyncTaskExecutor method destroy.

@Override
public void destroy() throws Exception {
    if (executor instanceof DisposableBean) {
        DisposableBean bean = (DisposableBean) executor;
        bean.destroy();
    }
}
Also used : DisposableBean(org.springframework.beans.factory.DisposableBean)

Example 3 with DisposableBean

use of org.springframework.beans.factory.DisposableBean in project spring-boot by spring-projects.

the class ConfigurationPropertiesBindingPostProcessor method freeLocalValidator.

private void freeLocalValidator() {
    try {
        Validator validator = this.localValidator;
        this.localValidator = null;
        if (validator != null) {
            ((DisposableBean) validator).destroy();
        }
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : DisposableBean(org.springframework.beans.factory.DisposableBean) Validator(org.springframework.validation.Validator) BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeansException(org.springframework.beans.BeansException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 4 with DisposableBean

use of org.springframework.beans.factory.DisposableBean in project uPortal by Jasig.

the class PortalShell method main.

public static void main(String[] args) throws Exception {
    final Options options = getOptions();
    final CommandLineParser parser = new PosixParser();
    final CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        printHelp(options);
        return;
    }
    final ApplicationContext applicationContext = PortalApplicationContextLocator.getApplicationContext();
    try {
        final Binding binding = new SpringBinding(applicationContext);
        binding.setVariable("logger", LOGGER);
        final CompilerConfiguration conf = new CompilerConfiguration(System.getProperties());
        final GroovyShell shell = new GroovyShell(binding, conf);
        if (commandLine.hasOption("script")) {
            final String scriptName = commandLine.getOptionValue("script");
            final File scriptFile = getAbsoluteFile(scriptName);
            shell.run(scriptFile, args);
        }
    } finally {
        if (applicationContext instanceof DisposableBean) {
            ((DisposableBean) applicationContext).destroy();
        }
    }
}
Also used : Binding(groovy.lang.Binding) Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) GroovyShell(groovy.lang.GroovyShell) CommandLine(org.apache.commons.cli.CommandLine) ApplicationContext(org.springframework.context.ApplicationContext) DisposableBean(org.springframework.beans.factory.DisposableBean) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Aggregations

DisposableBean (org.springframework.beans.factory.DisposableBean)4 Binding (groovy.lang.Binding)1 GroovyShell (groovy.lang.GroovyShell)1 File (java.io.File)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 PosixParser (org.apache.commons.cli.PosixParser)1 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)1 BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Validator (org.springframework.validation.Validator)1