Example usage for org.springframework.web.context.support XmlWebApplicationContext addApplicationListener

List of usage examples for org.springframework.web.context.support XmlWebApplicationContext addApplicationListener

Introduction

In this page you can find the example usage for org.springframework.web.context.support XmlWebApplicationContext addApplicationListener.

Prototype

@Override
    public void addApplicationListener(ApplicationListener<?> listener) 

Source Link

Usage

From source file:org.springsource.sinspctr.AdminMain.java

/**
* Launch stream server with the given home and transport
 * @throws IOException //from   w  ww  . j av  a 2 s.  c  om
*/
static InspctrServer launchStreamServer() throws IOException {
    XmlWebApplicationContext context = new XmlWebApplicationContext();
    context.setConfigLocation("classpath:" + CONFIG_ROOT + "sinspctr-server.xml");

    // Not making StreamServer a spring bean eases move to .war file if
    // needed
    final InspctrServer server = new InspctrServer(context, DEFAULT_PORT);
    server.afterPropertiesSet();
    server.start();
    StringBuilder runtimeInfo = new StringBuilder(
            String.format("Running in Local Mode on port: %s ", server.getPort()));
    System.out.println(BannerUtils.displayBanner(null, runtimeInfo.toString()));
    context.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
        @Override
        public void onApplicationEvent(ContextClosedEvent event) {
            server.stop();
        }
    });
    context.registerShutdownHook();
    return server;
}

From source file:org.springframework.yarn.examples.XdAppmasterRunner.java

@Override
protected ConfigurableApplicationContext getChildApplicationContext(String configLocation,
        ConfigurableApplicationContext parent) {

    log.info("Using xd.transport=" + System.getProperty("xd.transport"));
    log.info("Using xd.store=" + System.getProperty("xd.store"));
    log.info("Using xd.home=" + System.getProperty("xd.home"));

    XmlWebApplicationContext context = new XmlWebApplicationContext();
    context.setConfigLocation("classpath:" + DefaultContainer.XD_INTERNAL_CONFIG_ROOT + "admin-server.xml");

    final StreamServer server = new StreamServer(context, 8282);
    server.afterPropertiesSet();//  w  ww .  j  a v a2  s . co  m
    server.start();

    // when we get fix for 0-port trick in spring-xd
    //log.info("Streamserver tomcat port=" + server.getLocalPort());

    // context is already refreshed so just register singleton
    // not really a proper way to do it but serves the demo purpose
    // if streamserver could choose free port then below would
    // make much more sense
    parent.getBeanFactory().registerSingleton(YarnSystemConstants.DEFAULT_ID_AMTRACKSERVICE,
            new UrlAppmasterTrackService("http://localhost:" + server.getPort()));

    context.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
        @Override
        public void onApplicationEvent(ContextClosedEvent event) {
            server.stop();
        }
    });

    return context;
}