Example usage for org.springframework.context.event ContextClosedEvent getApplicationContext

List of usage examples for org.springframework.context.event ContextClosedEvent getApplicationContext

Introduction

In this page you can find the example usage for org.springframework.context.event ContextClosedEvent getApplicationContext.

Prototype

public final ApplicationContext getApplicationContext() 

Source Link

Document

Get the ApplicationContext that the event was raised for.

Usage

From source file:de.codecentric.boot.admin.services.RegistrationApplicationListener.java

@EventListener
@Order(Ordered.LOWEST_PRECEDENCE)//from   w w w .j  ava  2  s.com
public void onClosedContext(ContextClosedEvent event) {
    if (event.getApplicationContext().getParent() == null) {
        stopRegisterTask();

        if (autoDeregister) {
            registrator.deregister();
        }
    }
}

From source file:com.brienwheeler.apps.main.ContextMain.java

@Override
public void onApplicationEvent(ContextClosedEvent event) {
    final AbstractApplicationContext context = (AbstractApplicationContext) event.getApplicationContext();
    boolean waitAndSignal = false;

    synchronized (contextLaunchOrder) {
        contextLaunchOrder.remove(context);
        // if that was the last context and it self-terminated
        if (contextLaunchOrder.size() == 0 && !shuttingDown)
            waitAndSignal = true;/*  w w w . jav  a 2  s. c  o m*/
    }

    if (waitAndSignal) {
        // since the ContextClosedEvent actually comes at the start of the close process,
        // start a background thread to monitor the state of the context and signal
        // the thread waiting in onRun() when it is finished closing.
        new Thread() {
            @Override
            public void run() {
                while (context.isActive()) {
                    try {
                        Thread.sleep(100L);
                    } catch (InterruptedException e) {
                        log.error("interrupted while waiting for last context to finish shutdown");
                        Thread.currentThread().interrupt();
                    }
                }

                synchronized (contextLaunchOrder) {
                    contextLaunchOrder.notifyAll();
                }
            }
        }.start();
    }
}

From source file:org.kuali.rice.krad.datadictionary.ReloadingDataDictionary.java

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    // register a context close handler
    if (applicationContext instanceof ConfigurableApplicationContext) {
        ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
        context.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
            @Override// w ww . ja v a 2  s  .co  m
            public void onApplicationEvent(ContextClosedEvent e) {
                LOG.info("Context '" + e.getApplicationContext().getDisplayName()
                        + "' closed, shutting down URLMonitor scheduler");
                dictionaryUrlMonitor.shutdownScheduler();
            }
        });
    }
}

From source file:org.springframework.extensions.surf.util.AbstractLifecycleBean.java

public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent) event;
        ApplicationContext refreshContext = refreshEvent.getApplicationContext();
        if (refreshContext != null && refreshContext.equals(applicationContext)) {
            if (log.isDebugEnabled())
                log.debug("Bootstrapping component " + this.getClass().getName());
            onBootstrap(refreshEvent);// www. j  a  v a  2s .  c  om
        }
    } else if (event instanceof ContextClosedEvent) {
        ContextClosedEvent closedEvent = (ContextClosedEvent) event;
        ApplicationContext closedContext = closedEvent.getApplicationContext();
        if (closedContext != null && closedContext.equals(applicationContext)) {
            if (log.isDebugEnabled())
                log.debug("Shutting down component " + this.getClass().getName());
            onShutdown(closedEvent);
        }
    }
}