Java 类org.springframework.context.event.ApplicationContextEvent 实例源码

项目:astrix    文件:AstrixFrameworkBean.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    if (event instanceof ContextRefreshedEvent && !servicePublisherStarted) {
        // Application initialization complete. Export astrix-services.
        if (isServer()) {
            this.astrixContext.startServicePublisher();
        }
        servicePublisherStarted = true;
    } else if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent) {
        /*
         * What's the difference between the "stopped" and "closed" event? In our embedded
         * integration tests we only receive ContextClosedEvent
         */
        destroyAstrixContext();
    }
}
项目:camunda-bpm-platform    文件:SpringProcessApplication.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
  try {

    if (event instanceof ContextRefreshedEvent && !isDeployed) {
      // deploy the process application
      afterPropertiesSet();
    } else if (event instanceof ContextClosedEvent) {
      // undeploy the process application
      destroy();
    } else {
      // ignore
    }

  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
项目:emergentmud    文件:GameShutdownListener.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent) {
        List<Entity> everyone = entityRepository.findByXIsNotNullAndYIsNotNullAndZIsNotNull();
        GameOutput output = new GameOutput("[red]EmergentMUD is shutting down. Please check back later!");

        entityService.sendMessageToListeners(everyone, output);
    }
}
项目:gemini.blueprint    文件:BlueprintContainerServicePublisher.java   
public void onApplicationEvent(ApplicationContextEvent event) {
    // publish
    if (event instanceof ContextRefreshedEvent) {
        registerService(event.getApplicationContext());
    } else if (event instanceof ContextClosedEvent) {
        unregisterService();
    }
}
项目:OperatieBRP    文件:BrpApplicatieStartListener.java   
@Override
public final void onApplicationEvent(final ApplicationContextEvent event) {
    try {
        final ApplicationContext context = event.getApplicationContext();
        if (context instanceof XmlWebApplicationContext) {
            final XmlWebApplicationContext ctx = (XmlWebApplicationContext) context;
            String webContextName = ctx.getServletContext().getServletContextName();
            if (webContextName.contains("/")) {
                webContextName = webContextName.substring(webContextName.indexOf('/'));
            }
            ctx.setDisplayName(webContextName);
            MDC.put(LeveringVeld.MDC_APPLICATIE_NAAM, webContextName).close();
        }
        LOGGER.debug("Context event '{}'; id='{}', displayName='{}'", event.getClass().getSimpleName(), event
                .getApplicationContext().getId(), event.getApplicationContext().getDisplayName());

        if (event instanceof ContextClosedEvent) {
            LOGGER.info("==> Context voor applicatie '{}' is gestopt", event.getApplicationContext().getId());
        }
        /* Wanneer een applicatie is gestart, dan wordt een ContextRefreshedEvent gestuurt **/
        if (event instanceof ContextRefreshedEvent) {
            LOGGER.info("==> Context voor applicatie '{}' is gestart/herstart", event.getApplicationContext()
                    .getId());
            logJvmSettings();
        }
    } catch (final ApplicationContextException ex) {
        LOGGER.error("Fout bij het opstarten van de applicatiecontext bij event {}", event.toString(), ex);
    }


}
项目:tephra    文件:ContainerTest.java   
@Test
public void contextRefreshed() throws Exception {
    Assert.assertEquals(2, contextRefreshedList.size());
    for (int i = 0; i < contextRefreshedList.size(); i++)
        Assert.assertEquals(i + 1, numeric.toInt(contextRefreshedList.get(i)));

    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
        Assert.assertEquals(4 + i * 2, contextRefreshedList.size());
        for (int j = 0; j < contextRefreshedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
    }

    Field field = ContainerImpl.class.getDeclaredField("refreshedListeners");
    field.setAccessible(true);
    Object object = field.get(container);
    field.set(container, Optional.empty());
    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
        Assert.assertEquals(6, contextRefreshedList.size());
        for (int j = 0; j < contextRefreshedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
    }

    ((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
    });
    Assert.assertEquals(6, contextRefreshedList.size());
    for (int i = 0; i < contextRefreshedList.size(); i++)
        Assert.assertEquals(i % 2 + 1, numeric.toInt(contextRefreshedList.get(i)));

    field.set(container, object);
}
项目:tephra    文件:ContainerTest.java   
@Test
public void contextClosed() throws Exception {
    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
        Assert.assertEquals(2 + i * 2, contextClosedList.size());
        for (int j = 0; j < contextRefreshedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
    }

    Field field = ContainerImpl.class.getDeclaredField("closedListeners");
    field.setAccessible(true);
    Object object = field.get(container);
    field.set(container, Optional.empty());
    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
        Assert.assertEquals(4, contextClosedList.size());
        for (int j = 0; j < contextClosedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
    }

    ((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
    });
    Assert.assertEquals(4, contextClosedList.size());
    for (int i = 0; i < contextClosedList.size(); i++)
        Assert.assertEquals(i % 2 + 1, numeric.toInt(contextClosedList.get(i)));

    field.set(container, object);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AutoConfigurationReportLoggingInitializer.java   
protected void onApplicationEvent(ApplicationEvent event) {
    ConfigurableApplicationContext initializerApplicationContext = AutoConfigurationReportLoggingInitializer.this.applicationContext;
    if (event instanceof ContextRefreshedEvent) {
        if (((ApplicationContextEvent) event)
                .getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport();
        }
    }
    else if (event instanceof ApplicationFailedEvent) {
        if (((ApplicationFailedEvent) event)
                .getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport(true);
        }
    }
}
项目:HeliosStreams    文件:MetricRouterBuilder.java   
/**
 * {@inheritDoc}
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
    if(event.getApplicationContext()==appCtx) {
        if(event instanceof ContextRefreshedEvent) {
            start();
        } else if(event instanceof ContextStoppedEvent) {
            stop();
        }
    }       
}
项目:HeliosStreams    文件:HttpJsonMetricForwarder.java   
/**
 * {@inheritDoc}
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {       
    if(event.getApplicationContext()==appCtx) {
        if(event instanceof ContextRefreshedEvent) {
            try {
                start();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        } else if(event instanceof ContextClosedEvent) {
            stop();
        }
    }
}
项目:spring-boot-concourse    文件:AutoConfigurationReportLoggingInitializer.java   
protected void onApplicationEvent(ApplicationEvent event) {
    ConfigurableApplicationContext initializerApplicationContext = AutoConfigurationReportLoggingInitializer.this.applicationContext;
    if (event instanceof ContextRefreshedEvent) {
        if (((ApplicationContextEvent) event)
                .getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport();
        }
    }
    else if (event instanceof ApplicationFailedEvent) {
        if (((ApplicationFailedEvent) event)
                .getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport(true);
        }
    }
}
项目:contestparser    文件:AutoConfigurationReportLoggingInitializer.java   
protected void onApplicationEvent(ApplicationEvent event) {
    ConfigurableApplicationContext initializerApplicationContext = AutoConfigurationReportLoggingInitializer.this.applicationContext;
    if (event instanceof ContextRefreshedEvent) {
        if (((ApplicationContextEvent) event)
                .getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport();
        }
    }
    else if (event instanceof ApplicationFailedEvent) {
        if (((ApplicationFailedEvent) event)
                .getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport(true);
        }
    }
}
项目:mule-spring-boot-starter    文件:MuleContextInitializer.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    if (event instanceof ContextRefreshedEvent && event.getApplicationContext().getParent() == null) {
        startMuleContext(event.getApplicationContext());
    } else if (event instanceof ContextClosedEvent) {
        stopMuleContext();
    }
}
项目:jetstream    文件:ChannelFlowManagement.java   
public void onApplicationEvent(ApplicationEvent event) {
  if (event instanceof ContextRefreshedEvent || event instanceof ContextBeanChangedEvent) {
    ApplicationContext context = ((ApplicationContextEvent) event).getApplicationContext();
    boolean hasInboundChannels = !context.getBeansOfType(InboundChannel.class).isEmpty();
    int flowControls = context.getBeansOfType(PipelineFlowControl.class).size();
    // Ignore this, but if there are others, register for management
    if (hasInboundChannels || flowControls > 1) {
      Management.removeBeanOrFolder(getBeanName(), this);
      Management.addBean(getBeanName(), this);
    }
  }
}
项目:dynamise    文件:AppListener.java   
@Override
public void onApplicationEvent(ApplicationContextEvent arg0) {

    if (arg0 instanceof ContextRefreshedEvent) {
        LOG.warn("READY: " + this.version);
    } else if (arg0 instanceof ContextClosedEvent) {
        LOG.warn("SHUTDOWN: " + this.version);
    }
}
项目:bacoma    文件:ApplicationContextListener.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    ApplicationContext ctx = event.getApplicationContext();
    if(!(ctx instanceof AnnotationConfigWebApplicationContext))
        throw new RuntimeException("Initialization of the apllication-context failed!");

    try {
        FileSystemUtil fsu = ctx.getBean(FileSystemUtil.class);
        fsu.init();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    logger.info("*** Application-context successful initialized");
}
项目:learn_syllabus_plus_sync    文件:ScheduledJobManager.java   
/**
 * Listens for application lifecycle events (specifically start/stop),
 * and schedules the new run/cancels the next run as appropriate.
 * 
 * @param event the application event to process.
 */
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        this.applicationContext = event.getApplicationContext();
        this.startTimer();
    } else if (event instanceof ContextClosedEvent) {
        this.cancel();
        this.applicationContext = null;

        // This manually deregisters JDBC driver, which prevents Tomcat 7
        // from complaining about memory leaks from this class
        // XXX: Disabled as it's dangerous and Tomcat handles this much
        // better, even if it does complain
        /* Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            final Driver driver = drivers.nextElement();

            // Really ought to take the list of drivers to de-register from
            // application context
            if (driver instanceof com.microsoft.sqlserver.jdbc.SQLServerDriver) {
                try {
                    DriverManager.deregisterDriver(driver);
                } catch (SQLException e) {
                    log.error(String.format("Error deregistering driver %s", driver), e);
                }
            }
        } */
    }
}
项目:saos    文件:SolrLoader.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        load();
    } else if (event instanceof ContextClosedEvent) {
        shutdown();
    }
}
项目:cougar    文件:JMXControl.java   
/**
 * Return JMXControl bean from the ApplicationContext *if* the given event is
 * an {@link ApplicationContextEvent} (or null otherwise).
 * <p>
 * A utility method wrapping one way in which we'd call
 * {@link #getFromContext(ApplicationContext)}.
 */
public static JMXControl getFromEvent(ApplicationEvent event) {
    if (event instanceof ApplicationContextEvent) {
        return getFromContext(((ApplicationContextEvent) event).getApplicationContext());
    }
    else {
        return null;
    }
}
项目:alfresco-benchmark    文件:LifecycleController.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event)
{
    // Ignore events from different application contexts
    if (event.getApplicationContext() != ctx)
    {
        // Ignore
        return;
    }

    String eventName = event.getClass().getSimpleName();
    if (eventName.equals("ContextRefreshedEvent"))
    {
        // Only start once
        if (!started)
        {
            start();
            started = true;
        }
    }
    else if (eventName.equals("ContextClosedEvent"))
    {
        // Only stop once
        if (started)
        {
            stop();
            started = false;
        }
    }
}
项目:alfresco-repository    文件:ThumbnailRegistry.java   
public void onApplicationEvent(ApplicationContextEvent event)
{
    lifecycle.onApplicationEvent(event);
}
项目:alfresco-repository    文件:CMISConnector.java   
public void onApplicationEvent(ApplicationContextEvent event)
{
    lifecycle.onApplicationEvent(event);
}
项目:spring4-understanding    文件:AutoProxyLazyInitTests.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
}
项目:spring4-understanding    文件:AutoProxyLazyInitTests.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
}
项目:MBLive    文件:AppListener.java   
@Override
public void onApplicationEvent(ApplicationContextEvent applicationContextEvent) {
    List<Type> liveTypes = iLiveService.getAllType();
    ServletContext.liveTypes = liveTypes;
}
项目:mats    文件:MatsSpringAnnotationBeanPostProcessor.java   
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    log.info(LOG_PREFIX + "ApplicationListener.onApplicationEvent('" + event.getClass().getSimpleName() + "'): "
            + event);
}
项目:community-edition-old    文件:ThumbnailRegistry.java   
public void onApplicationEvent(ApplicationContextEvent event)
{
    lifecycle.onApplicationEvent(event);
}
项目:community-edition-old    文件:CMISConnector.java   
public void onApplicationEvent(ApplicationContextEvent event)
{
    lifecycle.onApplicationEvent(event);
}