Java 类org.springframework.boot.context.event.ApplicationStartedEvent 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    else if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    else if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent((ApplicationPreparedEvent) event);
    }
    else if (event instanceof ContextClosedEvent && ((ContextClosedEvent) event)
            .getApplicationContext().getParent() == null) {
        onContextClosedEvent();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplicationTests.java   
@Test
public void eventsOrder() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
    class ApplicationRunningEventListener
            implements ApplicationListener<ApplicationEvent> {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add((event));
        }
    }
    application.addListeners(new ApplicationRunningEventListener());
    this.context = application.run();
    assertThat(events).hasSize(5);
    assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
    assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
    assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
    assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
    assertThat(events.get(4)).isInstanceOf(ApplicationReadyEvent.class);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListenerTests.java   
@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
            TestCleanupLoggingSystem.class.getName());
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    GenericApplicationContext childContext = new GenericApplicationContext();
    childContext.setParent(this.context);
    this.initializer.onApplicationEvent(new ContextClosedEvent(childContext));
    assertThat(loggingSystem.cleanedUp).isFalse();
    this.initializer.onApplicationEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
    childContext.close();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestartApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        Restarter.getInstance()
                .prepare(((ApplicationPreparedEvent) event).getApplicationContext());
    }
    if (event instanceof ApplicationReadyEvent
            || event instanceof ApplicationFailedEvent) {
        Restarter.getInstance().finish();
        if (event instanceof ApplicationFailedEvent) {
            Restarter.getInstance().prepare(null);
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestartApplicationListenerTests.java   
private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
    assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
    assertThat(Restarter.getInstance().isFinished()).isFalse();
    listener.onApplicationEvent(
            new ApplicationPreparedEvent(application, ARGS, context));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
                context, new RuntimeException()));
    }
    else {
        listener.onApplicationEvent(
                new ApplicationReadyEvent(application, ARGS, context));
    }
}
项目:spring-boot-concourse    文件:LoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    else if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    else if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent((ApplicationPreparedEvent) event);
    }
    else if (event instanceof ContextClosedEvent && ((ContextClosedEvent) event)
            .getApplicationContext().getParent() == null) {
        onContextClosedEvent();
    }
}
项目:spring-boot-concourse    文件:SpringApplicationTests.java   
@Test
public void eventsOrder() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
    class ApplicationRunningEventListener
            implements ApplicationListener<ApplicationEvent> {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add((event));
        }
    }
    application.addListeners(new ApplicationRunningEventListener());
    this.context = application.run();
    assertThat(events).hasSize(5);
    assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
    assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
    assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
    assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
    assertThat(events.get(4)).isInstanceOf(ApplicationReadyEvent.class);
}
项目:spring-boot-concourse    文件:LoggingApplicationListenerTests.java   
@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
            TestCleanupLoggingSystem.class.getName());
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    GenericApplicationContext childContext = new GenericApplicationContext();
    childContext.setParent(this.context);
    this.initializer.onApplicationEvent(new ContextClosedEvent(childContext));
    assertThat(loggingSystem.cleanedUp).isFalse();
    this.initializer.onApplicationEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
    childContext.close();
}
项目:spring-boot-concourse    文件:RestartApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        Restarter.getInstance()
                .prepare(((ApplicationPreparedEvent) event).getApplicationContext());
    }
    if (event instanceof ApplicationReadyEvent
            || event instanceof ApplicationFailedEvent) {
        Restarter.getInstance().finish();
        if (event instanceof ApplicationFailedEvent) {
            Restarter.getInstance().prepare(null);
        }
    }
}
项目:spring-boot-concourse    文件:RestartApplicationListenerTests.java   
private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
    assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
    assertThat(Restarter.getInstance().isFinished()).isFalse();
    listener.onApplicationEvent(
            new ApplicationPreparedEvent(application, ARGS, context));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
                context, new RuntimeException()));
    }
    else {
        listener.onApplicationEvent(
                new ApplicationReadyEvent(application, ARGS, context));
    }
}
项目:contestparser    文件:SpringApplicationTests.java   
@Test
public void eventsOrder() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    final List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
    class ApplicationRunningEventListener
            implements ApplicationListener<ApplicationEvent> {
        @Override
        public void onApplicationEvent(ApplicationEvent event) {
            events.add((event));
        }
    }
    application.addListeners(new ApplicationRunningEventListener());
    this.context = application.run();
    assertThat(5, is(events.size()));
    assertThat(events.get(0), is(instanceOf(ApplicationStartedEvent.class)));
    assertThat(events.get(1),
            is(instanceOf(ApplicationEnvironmentPreparedEvent.class)));
    assertThat(events.get(2), is(instanceOf(ApplicationPreparedEvent.class)));
    assertThat(events.get(3), is(instanceOf(ContextRefreshedEvent.class)));
    assertThat(events.get(4), is(instanceOf(ApplicationReadyEvent.class)));
}
项目:contestparser    文件:RestartApplicationListenerTests.java   
private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(
            ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
    assertThat(Restarter.getInstance(), not(nullValue()));
    assertThat(Restarter.getInstance().isFinished(), equalTo(false));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS,
                context, new RuntimeException()));
    }
    else {
        listener.onApplicationEvent(
                new ApplicationReadyEvent(application, ARGS, context));
    }
}
项目:spring-boot-ssl-truststore-gen    文件:SslTrustStoreGeneratorListener.java   
public void onApplicationEvent(ApplicationStartedEvent event) {
    try {
        final String certificate = propertyResolver.getSystemProperty(TRUSTED_CA_CERTIFICATE_PROPERTY_NAME);
        if (!"".equals(certificate)) {
            LOGGER.info("Following additional CA Certificate has been defined in {} system property : {}", TRUSTED_CA_CERTIFICATE_PROPERTY_NAME, certificate);
            final TrustStoreInfo trustStoreInfo = trustStoreAppender.append(CertificateFactory.newInstance(certificate));
            System.setProperty(SSL_TRUST_STORE_SYSTEM_PROPERTY, trustStoreInfo.getTrustStorefFile().getAbsolutePath());
            LOGGER.info("Setting {} system property to {}", SSL_TRUST_STORE_SYSTEM_PROPERTY, trustStoreInfo.getTrustStorefFile().getAbsolutePath());
            System.setProperty(SSL_TRUST_STORE_PASSWORD_SYSTEM_PROPERTY, trustStoreInfo.getPassword());
            LOGGER.info("Setting {} system property to {}", SSL_TRUST_STORE_PASSWORD_SYSTEM_PROPERTY, trustStoreInfo.getPassword());
        } else {
            LOGGER.warn("No additional CA certificate has been defined using {} system property", TRUSTED_CA_CERTIFICATE_PROPERTY_NAME);
        }
    } catch (Exception e) {
        String message = "Cannot create truststore.";
        LOGGER.error(message);
        throw new IllegalStateException(message, e);
    }
    LOGGER.info("truststore generated");

}
项目:simple-hostel-management    文件:UpdateFilesListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {

    if (event instanceof ApplicationStartedEvent) {
       update();
    }

}
项目:springboot-analysis    文件:SimpleApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if(event instanceof ApplicationStartedEvent) {
        System.out.println("===== custom started event in initializer");
    } else if(event instanceof ApplicationReadyEvent) {
        System.out.println("===== custom ready event in initializer");
    }
}
项目:angular-spring-boot-micro-services-docker    文件:InspectLogPathListener.java   
@Override
public void onApplicationEvent(ApplicationStartedEvent event)
{



    System.setProperty("SQL_LOG_LEVEL","INFO");
    System.setProperty("SPRING_LOG_LEVEL","INFO");
    System.setProperty("ORM_LOG_LEVEL","INFO");
    if (System.getenv("log_dir") == null &&
        System.getProperty("log_dir") == null)
    {
        System.setProperty("log_dir",System.getProperty("java.io.tmpdir"));
    }

    if (System.getenv("SQL_LOG_LEVEL")!= null)
    {
        System.setProperty("SQL_LOG_LEVEL",System.getenv("SQL_LOG_LEVEL"));
    }
    if (System.getenv("SPRING_LOG_LEVEL")!= null)
    {
        System.setProperty("SPRING_LOG_LEVEL",System.getenv("SPRING_LOG_LEVEL"));
    }
    if (System.getenv("ORM_LOG_LEVEL")!= null)
    {
        System.setProperty("ORM_LOG_LEVEL",System.getenv("ORM_LOG_LEVEL"));
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListenerTests.java   
@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager().readConfiguration(
            JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
    new File(tmpDir() + "/spring.log").delete();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListenerTests.java   
@Test
public void parseArgsDoesntReplace() throws Exception {
    this.initializer.setSpringBootLogging(LogLevel.ERROR);
    this.initializer.setParseArgs(false);
    this.initializer.onApplicationEvent(new ApplicationStartedEvent(
            this.springApplication, new String[] { "--debug" }));
    this.initializer.initialize(this.context.getEnvironment(),
            this.context.getClassLoader());
    this.logger.debug("testatdebug");
    assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListenerTests.java   
@Test
public void shutdownHookIsNotRegisteredByDefault() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(),
            TestShutdownHandlerLoggingSystem.class.getName());
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListenerTests.java   
@Test
public void shutdownHookCanBeRegistered() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(),
            TestShutdownHandlerLoggingSystem.class.getName());
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
            "logging.register_shutdown_hook=true");
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNotNull();
    listener.shutdownHook.start();
    assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30,
            TimeUnit.SECONDS)).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:LoggingApplicationListenerTests.java   
@Test
public void closingContextCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
            TestCleanupLoggingSystem.class.getName());
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    this.initializer.onApplicationEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ApplicationPidFileWriterTests.java   
@Test
public void withNoEnvironment() throws Exception {
    File file = this.temporaryFolder.newFile();
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
    listener.setTriggerEventType(ApplicationStartedEvent.class);
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), new String[] {}));
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestartApplicationListener.java   
private void onApplicationStartedEvent(ApplicationStartedEvent event) {
    // It's too early to use the Spring environment but we should still allow
    // users to disable restart using a System property.
    String enabled = System.getProperty(ENABLED_PROPERTY);
    if (enabled == null || Boolean.parseBoolean(enabled)) {
        String[] args = event.getArgs();
        DefaultRestartInitializer initializer = new DefaultRestartInitializer();
        boolean restartOnInitialize = !AgentReloader.isActive();
        Restarter.initialize(args, false, initializer, restartOnInitialize);
    }
    else {
        Restarter.disable();
    }
}
项目:spring-boot-concourse    文件:LoggingApplicationListenerTests.java   
@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager().readConfiguration(
            JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
    new File(tmpDir() + "/spring.log").delete();
}
项目:spring-boot-concourse    文件:LoggingApplicationListenerTests.java   
@Test
public void parseArgsDoesntReplace() throws Exception {
    this.initializer.setSpringBootLogging(LogLevel.ERROR);
    this.initializer.setParseArgs(false);
    this.initializer.onApplicationEvent(new ApplicationStartedEvent(
            this.springApplication, new String[] { "--debug" }));
    this.initializer.initialize(this.context.getEnvironment(),
            this.context.getClassLoader());
    this.logger.debug("testatdebug");
    assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
}
项目:spring-boot-concourse    文件:LoggingApplicationListenerTests.java   
@Test
public void shutdownHookIsNotRegisteredByDefault() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(),
            TestShutdownHandlerLoggingSystem.class.getName());
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNull();
}
项目:spring-boot-concourse    文件:LoggingApplicationListenerTests.java   
@Test
public void shutdownHookCanBeRegistered() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(),
            TestShutdownHandlerLoggingSystem.class.getName());
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
            "logging.register_shutdown_hook=true");
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNotNull();
    listener.shutdownHook.start();
    assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30,
            TimeUnit.SECONDS)).isTrue();
}
项目:spring-boot-concourse    文件:LoggingApplicationListenerTests.java   
@Test
public void closingContextCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
            TestCleanupLoggingSystem.class.getName());
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    this.initializer.onApplicationEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
}
项目:spring-boot-concourse    文件:ApplicationPidFileWriterTests.java   
@Test
public void withNoEnvironment() throws Exception {
    File file = this.temporaryFolder.newFile();
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
    listener.setTriggerEventType(ApplicationStartedEvent.class);
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), new String[] {}));
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
项目:spring-boot-concourse    文件:RestartApplicationListener.java   
private void onApplicationStartedEvent(ApplicationStartedEvent event) {
    // It's too early to use the Spring environment but we should still allow
    // users to disable restart using a System property.
    String enabled = System.getProperty(ENABLED_PROPERTY);
    if (enabled == null || Boolean.parseBoolean(enabled)) {
        String[] args = event.getArgs();
        DefaultRestartInitializer initializer = new DefaultRestartInitializer();
        boolean restartOnInitialize = !AgentReloader.isActive();
        Restarter.initialize(args, false, initializer, restartOnInitialize);
    }
    else {
        Restarter.disable();
    }
}
项目:contestparser    文件:LoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    else if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent(
                (ApplicationEnvironmentPreparedEvent) event);
    }
    else if (event instanceof ContextClosedEvent) {
        onContextClosedEvent();
    }
}
项目:contestparser    文件:ClasspathLoggingApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        if (this.logger.isDebugEnabled()) {
            this.logger
                    .debug("Application started with classpath: " + getClasspath());
        }
    }
    else if (event instanceof ApplicationFailedEvent) {
        if (this.logger.isInfoEnabled()) {
            this.logger.info(
                    "Application failed to start with classpath: " + getClasspath());
        }
    }
}
项目:contestparser    文件:ClasspathLoggingApplicationListener.java   
@Override
public boolean supportsEventType(ResolvableType resolvableType) {
    Class<?> type = resolvableType.getRawClass();
    if (type == null) {
        return false;
    }
    return ApplicationStartedEvent.class.isAssignableFrom(type)
            || ApplicationFailedEvent.class.isAssignableFrom(type);
}
项目:contestparser    文件:LoggingApplicationListenerTests.java   
@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager().readConfiguration(
            JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
    new File(tmpDir() + "/spring.log").delete();
}
项目:contestparser    文件:LoggingApplicationListenerTests.java   
@Test
public void parseArgsDoesntReplace() throws Exception {
    this.initializer.setSpringBootLogging(LogLevel.ERROR);
    this.initializer.setParseArgs(false);
    this.initializer.onApplicationEvent(new ApplicationStartedEvent(
            this.springApplication, new String[] { "--debug" }));
    this.initializer.initialize(this.context.getEnvironment(),
            this.context.getClassLoader());
    this.logger.debug("testatdebug");
    assertThat(this.outputCapture.toString(), not(containsString("testatdebug")));
}
项目:contestparser    文件:LoggingApplicationListenerTests.java   
@Test
public void shutdownHookIsNotRegisteredByDefault() throws Exception {
    System.setProperty(LoggingSystem.class.getName(),
            NullShutdownHandlerLoggingSystem.class.getName());
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    this.initializer.initialize(this.context.getEnvironment(),
            this.context.getClassLoader());
    assertThat(NullShutdownHandlerLoggingSystem.shutdownHandlerRequested, is(false));
}
项目:contestparser    文件:LoggingApplicationListenerTests.java   
@Test
public void shutdownHookCanBeRegistered() throws Exception {
    System.setProperty(LoggingSystem.class.getName(),
            NullShutdownHandlerLoggingSystem.class.getName());
    EnvironmentTestUtils.addEnvironment(this.context,
            "logging.register_shutdown_hook:true");
    this.initializer.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
    this.initializer.initialize(this.context.getEnvironment(),
            this.context.getClassLoader());
    assertThat(NullShutdownHandlerLoggingSystem.shutdownHandlerRequested, is(true));
}
项目:contestparser    文件:ApplicationPidFileWriterTests.java   
@Test
public void withNoEnvironment() throws Exception {
    File file = this.temporaryFolder.newFile();
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
    listener.setTriggerEventType(ApplicationStartedEvent.class);
    listener.onApplicationEvent(
            new ApplicationStartedEvent(new SpringApplication(), new String[] {}));
    assertThat(FileCopyUtils.copyToString(new FileReader(file)),
            not(isEmptyString()));
}
项目:contestparser    文件:RestartApplicationListener.java   
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartedEvent) {
        onApplicationStartedEvent((ApplicationStartedEvent) event);
    }
    if (event instanceof ApplicationReadyEvent
            || event instanceof ApplicationFailedEvent) {
        Restarter.getInstance().finish();
    }
}
项目:contestparser    文件:RestartApplicationListener.java   
private void onApplicationStartedEvent(ApplicationStartedEvent event) {
    // It's too early to use the Spring environment but we should still allow
    // users to disable restart using a System property.
    String enabled = System.getProperty(ENABLED_PROPERTY);
    if (enabled == null || Boolean.parseBoolean(enabled)) {
        String[] args = event.getArgs();
        DefaultRestartInitializer initializer = new DefaultRestartInitializer();
        boolean restartOnInitialize = !AgentReloader.isActive();
        Restarter.initialize(args, false, initializer, restartOnInitialize);
    }
    else {
        Restarter.disable();
    }
}