org.springframework.context.ApplicationEvent

Here are the examples of the java api org.springframework.context.ApplicationEvent taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

316 Examples 7

19 View Source File : AllEventListener.java
License : Apache License 2.0
Project Creator : zq2599

@Override
public void onApplicationEvent(ApplicationEvent event) {
    Utils.printTrack("onApplicationEvent : " + event);
}

19 View Source File : ConfigsContextLifeCycle.java
License : Apache License 2.0
Project Creator : zhongxunking

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (!ConfigcenterProperties.INSTANCE.isEnable()) {
        return;
    }
    if (event instanceof ApplicationReadyEvent) {
        readyConfigsContext();
    } else {
        close();
    }
}

19 View Source File : AppApplicationListener.java
License : Apache License 2.0
Project Creator : zhaowb82

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextClosedEvent) {
        log.info("================:{}", "ContextClosedEvent");
        tcpServer.stopServer();
    }
    if (event instanceof ApplicationReadyEvent) {
        log.info("================:{}", "ApplicationReadyEvent");
        tcpServer.startServer();
    }
}

19 View Source File : Monitor.java
License : MIT License
Project Creator : yuriytkach

@Override
public void onApplicationEvent(ApplicationEvent event) {
    System.out.println(event.getClreplaced().getSimpleName() + " > " + event.getSource().toString());
}

19 View Source File : ServiceBean.java
License : Apache License 2.0
Project Creator : yunhaibin

public void onApplicationEvent(ApplicationEvent event) {
    if (ContextRefreshedEvent.clreplaced.getName().equals(event.getClreplaced().getName())) {
        if (isDelay() && !isExported() && !isUnexported()) {
            if (logger.isInfoEnabled()) {
                logger.info("The service ready on spring started. service: " + getInterface());
            }
            export();
        }
    }
}

19 View Source File : RestartApplicationListener.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationStartingEvent) {
        onApplicationStartingEvent((ApplicationStartingEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent((ApplicationPreparedEvent) event);
    }
    if (event instanceof ApplicationReadyEvent || event instanceof ApplicationFailedEvent) {
        Restarter.getInstance().finish();
    }
    if (event instanceof ApplicationFailedEvent) {
        onApplicationFailedEvent((ApplicationFailedEvent) event);
    }
}

19 View Source File : ConditionEvaluationReportLoggingListener.java
License : Apache License 2.0
Project Creator : yuanmabiji

protected void onApplicationEvent(ApplicationEvent event) {
    ConfigurableApplicationContext initializerApplicationContext = this.applicationContext;
    if (event instanceof ContextRefreshedEvent) {
        if (((ApplicationContextEvent) event).getApplicationContext() == initializerApplicationContext) {
            logAutoConfigurationReport();
        }
    } else if (event instanceof ApplicationFailedEvent && ((ApplicationFailedEvent) event).getApplicationContext() == initializerApplicationContext) {
        logAutoConfigurationReport(true);
    }
}

19 View Source File : LoggingApplicationListenerTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void multicastEvent(ApplicationEvent event) {
    multicastEvent(this.initializer, event);
}

19 View Source File : ClasspathLoggingApplicationListener.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (logger.isDebugEnabled()) {
        if (event instanceof ApplicationEnvironmentPreparedEvent) {
            logger.debug("Application started with clreplacedpath: " + getClreplacedpath());
        } else if (event instanceof ApplicationFailedEvent) {
            logger.debug("Application failed to start with clreplacedpath: " + getClreplacedpath());
        }
    }
}

19 View Source File : ConfigFileApplicationListener.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        onApplicationEnvironmentPreparedEvent((ApplicationEnvironmentPreparedEvent) event);
    }
    if (event instanceof ApplicationPreparedEvent) {
        onApplicationPreparedEvent(event);
    }
}

19 View Source File : ConfigFileApplicationListener.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void onApplicationPreparedEvent(ApplicationEvent event) {
    this.logger.switchTo(ConfigFileApplicationListener.clreplaced);
    addPostProcessors(((ApplicationPreparedEvent) event).getApplicationContext());
}

19 View Source File : SpringApplicationAdminMXBeanRegistrar.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationReadyEvent) {
        onApplicationReadyEvent((ApplicationReadyEvent) event);
    }
    if (event instanceof WebServerInitializedEvent) {
        onWebServerInitializedEvent((WebServerInitializedEvent) event);
    }
}

19 View Source File : ApplicationContextProvider.java
License : Apache License 2.0
Project Creator : yangjian102621

public static void publishEvent(ApplicationEvent event) {
    context.publishEvent(event);
}

19 View Source File : InitRightListener.java
License : MIT License
Project Creator : xujie01

@Override
public void onApplicationEvent(ApplicationEvent arg0) {
    // ������ˢ���¼�
    if (arg0 instanceof ContextRefreshedEvent) {
        // �������Ȩ��
        List<Right> rights = rightService.findAllEnreplacedies();
        Map<String, Right> map = new HashMap<String, Right>();
        for (Right r : rights) {
            map.put(r.getRightUrl(), r);
        }
        if (servletContext != null) {
            servletContext.setAttribute("all_rights_map", map);
        }
    }
}

19 View Source File : SpringUtil.java
License : MIT License
Project Creator : xkcoding

/**
 * 发布事件
 *
 * @param event 事件
 */
public static void publishEvent(ApplicationEvent event) {
    if (applicationContext == null) {
        return;
    }
    applicationContext.publishEvent(event);
}

19 View Source File : SpringUtil.java
License : GNU Lesser General Public License v3.0
Project Creator : xkcoding

/**
 * 发布事件
 *
 * @param event 事件
 */
public static void publishEvent(ApplicationEvent event) {
    if (context == null) {
        return;
    }
    try {
        context.publishEvent(event);
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }
}

19 View Source File : MultiRouteDataSource.java
License : MIT License
Project Creator : xk11961677

@Override
public void onApplicationEvent(ApplicationEvent event) {
    dynamicInitDatasource();
}

19 View Source File : SpringContextHolder.java
License : MIT License
Project Creator : wligang

/**
 * 发布事件
 *
 * @param event
 */
public static void publishEvent(ApplicationEvent event) {
    if (applicationContext == null) {
        return;
    }
    applicationContext.publishEvent(event);
}

19 View Source File : EmbeddedSpringSaturnApplication.java
License : Apache License 2.0
Project Creator : vipshop

@Override
public void onApplicationEvent(ApplicationEvent event) {
    try {
        if (event instanceof ContextRefreshedEvent) {
            ContextRefreshedEvent contextRefreshedEvent = (ContextRefreshedEvent) event;
            applicationContext = contextRefreshedEvent.getApplicationContext();
            if (embeddedSaturn == null) {
                embeddedSaturn = new EmbeddedSaturn();
                embeddedSaturn.setSaturnApplication(this);
                embeddedSaturn.start();
            }
        } else if (event instanceof ContextClosedEvent) {
            if (embeddedSaturn != null) {
                embeddedSaturn.stopGracefully();
                embeddedSaturn = null;
            }
        }
    } catch (Exception e) {
        logger.warn("exception happened on event: " + event, e);
        if (!ignoreExceptions) {
            throw new RuntimeException(e);
        }
    }
}

19 View Source File : ApplicationListenerMethodTransactionalAdapter.java
License : MIT License
Project Creator : Vip-Augus

private TransactionSynchronization createTransactionSynchronization(ApplicationEvent event) {
    return new TransactionSynchronizationEventAdapter(this, event, this.annotation.phase());
}

19 View Source File : ApplicationListenerMethodTransactionalAdapter.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (TransactionSynchronizationManager.isSynchronizationActive()) {
        TransactionSynchronization transactionSynchronization = createTransactionSynchronization(event);
        TransactionSynchronizationManager.registerSynchronization(transactionSynchronization);
    } else if (this.annotation.fallbackExecution()) {
        if (this.annotation.phase() == TransactionPhase.AFTER_ROLLBACK && logger.isWarnEnabled()) {
            logger.warn("Processing " + event + " as a fallback execution on AFTER_ROLLBACK phase");
        }
        processEvent(event);
    } else {
        // No transactional event execution at all
        if (logger.isDebugEnabled()) {
            logger.debug("No transaction is active - skipping " + event);
        }
    }
}

19 View Source File : EventPublishingTestExecutionListenerTests.java
License : MIT License
Project Creator : Vip-Augus

private void replacedertNoEvent(Clreplaced<? extends TestContextEvent> eventClreplaced, Consumer<TestContext> callback) {
    callback.accept(testContext);
    // The listener attempted to publish the event...
    verify(testContext, times(1)).publishEvent(eventFactory.capture());
    // But the event was not actually published since the ApplicationContext
    // was not available.
    verify(applicationContext, never()).publishEvent(any());
    // In any case, we can still verify the type of event that would have
    // been published.
    ApplicationEvent event = eventFactory.getValue().apply(testContext);
    replacedertThat(event, instanceOf(eventClreplaced));
    replacedertThat(event.getSource(), equalTo(testContext));
}

19 View Source File : EventPublishingTestExecutionListenerTests.java
License : MIT License
Project Creator : Vip-Augus

private void replacedertEvent(Clreplaced<? extends TestContextEvent> eventClreplaced, Consumer<TestContext> callback) {
    callback.accept(testContext);
    // The listener attempted to publish the event...
    verify(testContext, times(1)).publishEvent(eventFactory.capture());
    // The listener successfully published the event...
    verify(applicationContext, times(1)).publishEvent(any());
    // Verify the type of event that was published.
    ApplicationEvent event = eventFactory.getValue().apply(testContext);
    replacedertThat(event, instanceOf(eventClreplaced));
    replacedertThat(event.getSource(), equalTo(testContext));
}

19 View Source File : StubWebApplicationContext.java
License : MIT License
Project Creator : Vip-Augus

// ---------------------------------------------------------------------
// Other
// ---------------------------------------------------------------------
@Override
public void publishEvent(ApplicationEvent event) {
}

19 View Source File : MultiServerUserRegistry.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (this.delegateApplicationEvents) {
        ((SmartApplicationListener) this.localRegistry).onApplicationEvent(event);
    }
}

19 View Source File : FactoryBeanAndApplicationListener.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void onApplicationEvent(ApplicationEvent event) {
}

19 View Source File : ApplicationListenerMethodAdapterTests.java
License : MIT License
Project Creator : Vip-Augus

private void invokeListener(Method method, ApplicationEvent event) {
    ApplicationListenerMethodAdapter adapter = createTestInstance(method);
    adapter.onApplicationEvent(event);
}

19 View Source File : SourceFilteringListener.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event.getSource() == this.source) {
        onApplicationEventInternal(event);
    }
}

19 View Source File : SourceFilteringListener.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Actually process the event, after having filtered according to the
 * desired event source already.
 * <p>The default implementation invokes the specified delegate, if any.
 * @param event the event to process (matching the specified source)
 */
protected void onApplicationEventInternal(ApplicationEvent event) {
    if (this.delegate == null) {
        throw new IllegalStateException("Must specify a delegate object or override the onApplicationEventInternal method");
    }
    this.delegate.onApplicationEvent(event);
}

19 View Source File : SimpleApplicationEventMulticaster.java
License : MIT License
Project Creator : Vip-Augus

private ResolvableType resolveDefaultEventType(ApplicationEvent event) {
    return ResolvableType.forInstance(event);
}

19 View Source File : SimpleApplicationEventMulticaster.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void multicastEvent(ApplicationEvent event) {
    multicastEvent(event, resolveDefaultEventType(event));
}

19 View Source File : SimpleApplicationEventMulticaster.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Invoke the given listener with the given event.
 * @param listener the ApplicationListener to invoke
 * @param event the current event to propagate
 * @since 4.1
 */
protected void invokeListener(ApplicationListener<?> listener, ApplicationEvent event) {
    ErrorHandler errorHandler = getErrorHandler();
    if (errorHandler != null) {
        try {
            doInvokeListener(listener, event);
        } catch (Throwable err) {
            errorHandler.handleError(err);
        }
    } else {
        doInvokeListener(listener, event);
    }
}

19 View Source File : GenericApplicationListenerAdapter.java
License : MIT License
Project Creator : Vip-Augus

@Override
public void onApplicationEvent(ApplicationEvent event) {
    this.delegate.onApplicationEvent(event);
}

19 View Source File : EventPublicationInterceptor.java
License : MIT License
Project Creator : Vip-Augus

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Object retVal = invocation.proceed();
    replacedert.state(this.applicationEventClreplacedConstructor != null, "No ApplicationEvent clreplaced set");
    ApplicationEvent event = (ApplicationEvent) this.applicationEventClreplacedConstructor.newInstance(invocation.getThis());
    replacedert.state(this.applicationEventPublisher != null, "No ApplicationEventPublisher available");
    this.applicationEventPublisher.publishEvent(event);
    return retVal;
}

19 View Source File : EventExpressionRootObject.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Root object used during event listener expression evaluation.
 *
 * @author Stephane Nicoll
 * @since 4.2
 */
clreplaced EventExpressionRootObject {

    private final ApplicationEvent event;

    private final Object[] args;

    public EventExpressionRootObject(ApplicationEvent event, Object[] args) {
        this.event = event;
        this.args = args;
    }

    public ApplicationEvent getEvent() {
        return this.event;
    }

    public Object[] getArgs() {
        return this.args;
    }
}

19 View Source File : EventExpressionEvaluator.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Determine if the condition defined by the specified expression evaluates
 * to {@code true}.
 */
public boolean condition(String conditionExpression, ApplicationEvent event, Method targetMethod, AnnotatedElementKey methodKey, Object[] args, @Nullable BeanFactory beanFactory) {
    EventExpressionRootObject root = new EventExpressionRootObject(event, args);
    MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(root, targetMethod, args, getParameterNameDiscoverer());
    if (beanFactory != null) {
        evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
    }
    return (Boolean.TRUE.equals(getExpression(this.conditionCache, methodKey, conditionExpression).getValue(evaluationContext, Boolean.clreplaced)));
}

19 View Source File : ApplicationListenerMethodAdapter.java
License : MIT License
Project Creator : Vip-Augus

/**
 * Process the specified {@link ApplicationEvent}, checking if the condition
 * matches and handling a non-null result, if any.
 */
public void processEvent(ApplicationEvent event) {
    Object[] args = resolveArguments(event);
    if (shouldHandle(event, args)) {
        Object result = doInvoke(args);
        if (result != null) {
            handleResult(result);
        } else {
            logger.trace("No result object given - no result to handle");
        }
    }
}

19 View Source File : BaseServiceImpl.java
License : MIT License
Project Creator : uhonliu

public void pushEvent(ApplicationEvent applicationEvent) {
    ContextLoader.getCurrentWebApplicationContext().publishEvent(applicationEvent);
}

19 View Source File : LogoApplicationListener.java
License : Apache License 2.0
Project Creator : tryob

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof StartedApplicationEvent) {
        printLogo();
    }
}

19 View Source File : ApplicationStartedEventListener.java
License : Apache License 2.0
Project Creator : TraceNature

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        ConfigurableEnvironment environment = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
        String somePropLevel = environment.getProperty("logging.level.root");
        String someProp = environment.getProperty("syncer.config.path.logfile");
        String logfileNameProp = environment.getProperty("syncer.config.path.logfileName");
        System.setProperty("logPath", someProp);
        System.setProperty("logLevel", somePropLevel);
        System.setProperty("logFileName", logfileNameProp);
        System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
    }
}

19 View Source File : SpringBootPlatform.java
License : Apache License 2.0
Project Creator : thomasdarimont

public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationReadyEvent) {
        runStartupHook();
    } else if (event instanceof ContextStoppedEvent) {
        runShutdownHook();
    }
}

@Override
public void onApplicationEvent(@NonNull ApplicationEvent event) {
    if (!(event instanceof ApplicationEnvironmentPreparedEvent)) {
        return;
    }
    ApplicationEnvironmentPreparedEvent envEvent = (ApplicationEnvironmentPreparedEvent) event;
    ConfigurableEnvironment env = envEvent.getEnvironment();
    try {
        Resource resource = new ClreplacedPathResource("keycloak-defaults.yml");
        if (!resource.exists()) {
            return;
        }
        log.info("Loading default keycloak properties configuration from: {}", resource.getURI());
        YamlPropertySourceLoader sourceLoader = new YamlPropertySourceLoader();
        List<PropertySource<?>> yamlTestProperties = sourceLoader.load("keycloak-defaults.yml", resource);
        if (!yamlTestProperties.isEmpty()) {
            env.getPropertySources().addLast(yamlTestProperties.get(0));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

19 View Source File : TestListener.java
License : Apache License 2.0
Project Creator : tedburner

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof TestEvent) {
        TestEvent testEvent = (TestEvent) event;
        testEvent.print();
    }
}

19 View Source File : DubboHolderListener.java
License : Apache License 2.0
Project Creator : teaey

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationPreparedEvent) {
        if (running == Boolean.FALSE)
            running = Boolean.TRUE;
        if (holdThread == null) {
            holdThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace(Thread.currentThread().getName());
                    }
                    while (running && !Thread.currentThread().isInterrupted()) {
                        try {
                            Thread.sleep(2000);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }, "Dubbo-Holder");
            holdThread.setDaemon(false);
            holdThread.start();
        }
    }
    if (event instanceof ContextClosedEvent) {
        running = Boolean.FALSE;
        if (null != holdThread) {
            holdThread.interrupt();
            holdThread = null;
        }
    }
}

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (!(event instanceof ApplicationReadyEvent))
        return;
    ConfigurableListableBeanFactory beanFactory = ((ApplicationReadyEvent) event).getApplicationContext().getBeanFactory();
    ZipkinHealthIndicator healthIndicator = beanFactory.getBean(ZipkinHealthIndicator.clreplaced);
    for (Component component : beanFactory.getBeansOfType(Component.clreplaced).values()) {
        healthIndicator.addComponent(component);
    }
}

19 View Source File : SpringEventPublisher.java
License : Apache License 2.0
Project Creator : SpringCloud

public void publishEvent(ApplicationEvent event) {
    applicationEventPublisher.publishEvent(event);
}

@Test
public void doesNotDestroyGemFireMockObjectsOnRandomApplicationEvent() {
    ApplicationEvent mockEvent = mock(ApplicationEvent.clreplaced);
    this.listener.onApplicationEvent(mockEvent);
    verify(this.listener, never()).destroyGemFireMockObjects();
}

@Test
public void onApplicationEventCallsCollectGemFireResourceAndCollectGemFireDiskStoreFiles() {
    ApplicationEvent mockApplicationEvent = mock(ApplicationEvent.clreplaced);
    GemFireResourceCollectorApplicationListener listener = spy(GemFireResourceCollectorApplicationListener.create());
    doReturn(true).when(listener).isGemFireResourceCollectorEvent(any());
    doReturn(true).when(listener).isTryCleanDiskStoreFilesEnabled();
    doNothing().when(listener).collectGemFireDiskStoreFiles();
    doNothing().when(listener).collectGemFireResources(any());
    listener.onApplicationEvent(mockApplicationEvent);
    verify(listener, times(1)).isGemFireResourceCollectorEvent(eq(mockApplicationEvent));
    verify(listener, times(1)).collectGemFireResources(eq(GemFireResourceCollectorApplicationListener.DEFAULT_SEARCH_DIRECTORY));
    verify(listener, times(1)).isTryCleanDiskStoreFilesEnabled();
    verify(listener, times(1)).collectGemFireDiskStoreFiles();
}

@Test
public void isGemFireCollectorEventWithNonMatchingEventReturnsFalse() {
    ApplicationEvent mockEvent = mock(AfterTestClreplacedEvent.clreplaced);
    replacedertThat(GemFireResourceCollectorApplicationListener.create(AfterTestMethodEvent.clreplaced).isGemFireResourceCollectorEvent(mockEvent)).isFalse();
}

@Test
public void isGemFireCollectorEventWithMatchingEventSubtypeReturnsTrue() {
    ApplicationEvent mockEvent = mock(AfterTestMethodEventSubType.clreplaced);
    replacedertThat(GemFireResourceCollectorApplicationListener.create(AfterTestMethodEvent.clreplaced).isGemFireResourceCollectorEvent(mockEvent)).isTrue();
}

See More Examples