Example usage for org.springframework.beans.factory.config ConfigurableBeanFactory containsSingleton

List of usage examples for org.springframework.beans.factory.config ConfigurableBeanFactory containsSingleton

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConfigurableBeanFactory containsSingleton.

Prototype

boolean containsSingleton(String beanName);

Source Link

Document

Check if this registry contains a singleton instance with the given name.

Usage

From source file:org.red5.server.jboss.JbossLoader.java

/**
 * Shut server down//ww w  . ja v a 2  s .c o  m
 */
public void stop() {
    logger.info("Shutting down jboss context");
    try {
        //prepare spring for shutdown
        Introspector.flushCaches();
        //shutdown our jmx agent
        JMXAgent.shutdown();
        //shutdown spring
        FileSystemXmlApplicationContext appContext = (FileSystemXmlApplicationContext) getApplicationContext();
        ConfigurableBeanFactory factory = appContext.getBeanFactory();
        if (factory.containsSingleton("default.context")) {
            for (String scope : factory.getRegisteredScopeNames()) {
                logger.debug("Registered scope: " + scope);
            }
            for (String singleton : factory.getSingletonNames()) {
                logger.debug("Registered singleton: " + singleton);
                //factory.destroyScopedBean(singleton);
            }
            factory.destroySingletons();
        }
        appContext.close();
        LogFactory.release(Thread.currentThread().getContextClassLoader());
    } catch (Exception e) {
        logger.warn("Jboss could not be stopped", e);
    }
}

From source file:org.red5.server.plugin.definst.DefinstPlugin.java

@Override
public void doStart() throws Exception {
    super.doStart();

    // add the context to the parent, this will be red5.xml
    ConfigurableBeanFactory factory = ((ConfigurableApplicationContext) context).getBeanFactory();
    // if parent context was not set then lookup red5.common
    log.debug("Lookup common - bean:{} local:{} singleton:{}",
            new Object[] { factory.containsBean("red5.common"), factory.containsLocalBean("red5.common"),
                    factory.containsSingleton("red5.common"), });
    parentContext = (ApplicationContext) factory.getBean("red5.common");

    //create app context
    appContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/definst.xml" }, true,
            parentContext);//from   w  w w  .  j  a  v a  2  s. com

    //get a ref to the "default" global scope
    GlobalScope global = (GlobalScope) server.getGlobal("default");

    //create a scope resolver
    ScopeResolver scopeResolver = new ScopeResolver();
    scopeResolver.setGlobalScope(global);

    //create a context - this takes the place of the previous web context
    Context ctx = new Context(appContext, appName);
    ctx.setClientRegistry(new ClientRegistry());
    ctx.setMappingStrategy(new MappingStrategy());
    ctx.setPersistanceStore(global.getStore());
    ctx.setScopeResolver(scopeResolver);
    ctx.setServiceInvoker(new ServiceInvoker());

    //create a handler
    handler = new DefinstHandler();

    //create a scope for the admin
    //      Scope scope = new Scope.Builder((IScope) global, "scope", appName, false).build();
    //      scope.setContext(ctx);
    //      scope.setHandler(handler);

    server.addMapping(hostName, appName, "default");

    //      if (global.addChildScope(scope)) {
    //         log.info("Scope was added to global (default) scope");
    //      } else {
    //         log.warn("Scope was not added to global (default) scope");
    //      }
    //      
    //      //start the scope
    //      scope.start();

}

From source file:org.red5.server.war.MainServlet.java

/**
 * Clearing the in-memory configuration parameters, we will receive
 * notification that the servlet context is about to be shut down
 *//*from   ww w.  j a  v a2  s . c  o  m*/
public void contextDestroyed(ServletContextEvent sce) {
    logger.info("Webapp shutdown");
    // XXX Paul: grabbed this from
    // http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go
    // in hopes that we can clear all the issues with J2EE containers during
    // shutdown
    try {
        // prepare spring for shutdown
        Introspector.flushCaches();
        // dereg any drivers
        for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) {
            Driver driver = (Driver) e.nextElement();
            if (driver.getClass().getClassLoader() == getClass().getClassLoader()) {
                DriverManager.deregisterDriver(driver);
            }
        }
        // shutdown jmx
        JMXAgent.shutdown();
        // shutdown spring
        // get web application context from the servlet context
        ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) servletContext
                .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
        if (factory.containsSingleton("default.context")) {
            for (String scope : factory.getRegisteredScopeNames()) {
                logger.debug("Registered scope: " + scope);
            }
            for (String singleton : factory.getSingletonNames()) {
                logger.debug("Registered singleton: " + singleton);
                // factory.destroyScopedBean(singleton);
            }
            factory.destroySingletons();
        }
        servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        applicationContext.close();
        // http://jakarta.apache.org/commons/logging/guide.html#Classloader_and_Memory_Management
        // http://wiki.apache.org/jakarta-commons/Logging/UndeployMemoryLeak?action=print
        // LogFactory.release(Thread.currentThread().getContextClassLoader());
    } catch (Throwable e) {
        // may get a java.lang.StackOverflowError when shutting appcontext
        // down in jboss
        e.printStackTrace();
    }
}