Example usage for org.springframework.context.support AbstractXmlApplicationContext destroy

List of usage examples for org.springframework.context.support AbstractXmlApplicationContext destroy

Introduction

In this page you can find the example usage for org.springframework.context.support AbstractXmlApplicationContext destroy.

Prototype

@Deprecated
public void destroy() 

Source Link

Document

Callback for destruction of this instance, originally attached to a DisposableBean implementation (not anymore in 5.0).

Usage

From source file:com.turbospaces.api.EmbeddedJSpaceRunner.java

/**
 * launcher method/*ww  w  . jav  a 2 s .co  m*/
 * 
 * @param args
 *            [1 argument = application context path]
 * @throws Exception
 *             re-throw execution errors if any
 */
public static void main(final String... args) throws Exception {
    JVMUtil.gcOnExit();
    String appContextPath = args[0];
    if (System.getProperty(Global.IPv4) == null && System.getProperty(Global.IPv6) == null)
        System.setProperty(Global.IPv4, Boolean.TRUE.toString());
    System.setProperty(Global.CUSTOM_LOG_FACTORY, JGroupsCustomLoggerFactory.class.getName());

    LOGGER.info("Welcome to turbospaces:version = {}, build date = {}", SpaceUtility.projectVersion(),
            SpaceUtility.projecBuildTimestamp());
    LOGGER.info("{}: launching configuration {}", EmbeddedJSpaceRunner.class.getSimpleName(), appContextPath);
    AbstractXmlApplicationContext c = appContextPath.startsWith("file")
            ? new FileSystemXmlApplicationContext(appContextPath)
            : new ClassPathXmlApplicationContext(appContextPath);
    c.getBeansOfType(JSpace.class);
    c.registerShutdownHook();
    Collection<SpaceConfiguration> configurations = c.getBeansOfType(SpaceConfiguration.class).values();
    for (SpaceConfiguration spaceConfiguration : configurations)
        spaceConfiguration.joinNetwork();
    LOGGER.info("all jspaces joined network, notifying waiting threads...");
    synchronized (joinNetworkMonitor) {
        joinNetworkMonitor.notifyAll();
    }

    while (!Thread.currentThread().isInterrupted())
        synchronized (c) {
            try {
                c.wait(TimeUnit.SECONDS.toMillis(1));
            } catch (InterruptedException e) {
                LOGGER.info("got interruption signal, terminating jspaces... stack_trace = {}",
                        Throwables.getStackTraceAsString(e));
                Thread.currentThread().interrupt();
                Util.printThreads();
            }
        }

    c.destroy();
}