当前位置: 首页>>代码示例>>Java>>正文


Java ApplicationListener类代码示例

本文整理汇总了Java中org.springframework.context.ApplicationListener的典型用法代码示例。如果您正苦于以下问题:Java ApplicationListener类的具体用法?Java ApplicationListener怎么用?Java ApplicationListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ApplicationListener类属于org.springframework.context包,在下文中一共展示了ApplicationListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: invokeListener

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
/**
 * Invoke the given listener with the given event.
 * @param listener the ApplicationListener to invoke
 * @param event the current event to propagate
 * @since 4.1
 */
@SuppressWarnings({"unchecked", "rawtypes"})
protected void invokeListener(ApplicationListener listener, ApplicationEvent event) {
	ErrorHandler errorHandler = getErrorHandler();
	if (errorHandler != null) {
		try {
			listener.onApplicationEvent(event);
		}
		catch (Throwable err) {
			errorHandler.handleError(err);
		}
	}
	else {
		listener.onApplicationEvent(event);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:SimpleApplicationEventMulticaster.java

示例2: multicastEventInternal

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void multicastEventInternal(final ApplicationEvent event) {
    for (final ApplicationListener listener : getApplicationListeners(event)) {
        Executor executor = getTaskExecutor();
        if (executor != null) {
            executor.execute(new Runnable() {
                public void run() {
                    listener.onApplicationEvent(event);
                }
            });
        }
        else {
            listener.onApplicationEvent(event);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:SafeApplicationEventMulticaster.java

示例3: multicastEvent

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void multicastEvent(final ApplicationEvent event) {
	for (final ApplicationListener listener : getApplicationListeners(event)) {
		Executor executor = getTaskExecutor();
		if (executor != null) {
			executor.execute(new Runnable() {
				@Override
				public void run() {
					listener.onApplicationEvent(event);
				}
			});
		}
		else {
			listener.onApplicationEvent(event);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:SimpleApplicationEventMulticaster.java

示例4: main

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("collector backup start successfully");

    KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer");
    Task task = (Task) context.getBean("backupTask");

    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task));
    task.doTask();
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java

示例5: invokeListener

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
/**
 * Invoke the given listener with the given event.
 * @param listener the ApplicationListener to invoke
 * @param event the current event to propagate
 * @since 4.1
 */
@SuppressWarnings({"unchecked", "rawtypes"})
protected void invokeListener(ApplicationListener listener, ApplicationEvent event) {
	ErrorHandler errorHandler = getErrorHandler();
	if (errorHandler != null) {
		try {
			listener.onApplicationEvent(event);
		}
		catch (Throwable err) {
			errorHandler.handleError(err);
		}
	}
	else {
		try {
			listener.onApplicationEvent(event);
		}
		catch (ClassCastException ex) {
			// Possibly a lambda-defined listener which we could not resolve the generic event type for
			LogFactory.getLog(getClass()).debug("Non-matching event type for listener: " + listener, ex);
		}
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:28,代码来源:SimpleApplicationEventMulticaster.java

示例6: multicastEvent

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void multicastEvent(ApplicationEvent event, ResolvableType eventType) {

	ResolvableType type = eventType == null ? ResolvableType.forInstance(event) : eventType;
	Collection<ApplicationListener<?>> listeners = getApplicationListeners(event, type);

	if (listeners.isEmpty()) {
		return;
	}

	List<ApplicationListener<?>> transactionalListeners = listeners.stream()//
			.filter(PersistentApplicationEventMulticaster::isTransactionalApplicationEventListener)//
			.collect(Collectors.toList());

	if (!transactionalListeners.isEmpty()) {

		Object eventToPersist = getEventToPersist(event);

		registry.getObject().store(eventToPersist, transactionalListeners);
		// EventStore.persist(eventThis)
		// SpringMVC Controller Atom Feed
	}

	for (ApplicationListener listener : listeners) {
		listener.onApplicationEvent(event);
	}
}
 
开发者ID:olivergierke,项目名称:spring-domain-events,代码行数:29,代码来源:PersistentApplicationEventMulticaster.java

示例7: notifyListeners

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
private void notifyListeners(String description, int count)
{
    if (!this.applicationListeners.isEmpty())
    {
        IndexEvent event = new IndexEvent(this, description, count);
        for (ApplicationListener listener : this.applicationListeners)
        {
            listener.onApplicationEvent(event);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:12,代码来源:IndexInfo.java

示例8: broadcastEvent

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
/**
 * Broadcast event.
 * 
 * @param event
 *            the event
 */
private void broadcastEvent(PropertyBackedBeanEvent event)
{
    // If the system is up and running, broadcast the event immediately
    if (this.isSchemaAvailable && this.wasDictionaryBootstrapped)
    {
        // If we have a transaction, the changed properties in it should be updated earlier,
        // then the bean restart message will be sent to other node
        // see ALF-20066
        if (AlfrescoTransactionSupport.getTransactionId() != null &&
                (event instanceof PropertyBackedBeanStartedEvent ||
                event instanceof PropertyBackedBeanStoppedEvent))
        {
            this.afterTransactionEvents.add(event);
            AlfrescoTransactionSupport.bindListener(this);
        }
        else
        {
            for (ApplicationListener listener : this.listeners)
            {
                listener.onApplicationEvent(event);
            }
        }
    }
    // Otherwise, defer broadcasting until the schema available event is handled
    else
    {
        this.deferredEvents.add(event);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:36,代码来源:DefaultPropertyBackedBeanRegistry.java

示例9: afterCommit

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
@Override
public void afterCommit()
{
    for (ApplicationEvent event : this.afterTransactionEvents)
    {
        for (ApplicationListener listener : this.listeners)
        {
            listener.onApplicationEvent(event);
        }
    }
    this.afterTransactionEvents.clear();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:13,代码来源:DefaultPropertyBackedBeanRegistry.java

示例10: postProcessAfterInitialization

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
	if (bean instanceof ApplicationListener) {
		// potentially not detected as a listener by getBeanNamesForType retrieval
		Boolean flag = this.singletonNames.get(beanName);
		if (Boolean.TRUE.equals(flag)) {
			// singleton bean (top-level or inner): register on the fly
			this.applicationContext.addApplicationListener((ApplicationListener<?>) bean);
		}
		else if (flag == null) {
			if (logger.isWarnEnabled() && !this.applicationContext.containsBean(beanName)) {
				// inner bean with other scope - can't reliably process events
				logger.warn("Inner bean '" + beanName + "' implements ApplicationListener interface " +
						"but is not reachable for event multicasting by its containing ApplicationContext " +
						"because it does not have singleton scope. Only top-level listener beans are allowed " +
						"to be of non-singleton scope.");
			}
			this.singletonNames.put(beanName, Boolean.FALSE);
		}
	}
	return bean;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:PostProcessorRegistrationDelegate.java

示例11: should_stop_success_demo_first

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
@Test
public void should_stop_success_demo_first() throws Throwable {
    cleanFolder("flowCliE");

    CountDownLatch countDownLatch = new CountDownLatch(1);
    applicationEventMulticaster.addApplicationListener((ApplicationListener<PluginStatusChangeEvent>) event -> {
        if (ImmutableMultiset.of(PluginStatus.INSTALLING).contains(event.getPluginStatus())) {
            countDownLatch.countDown();
        }
    });

    pluginService.install("flowCliE");
    countDownLatch.await(30, TimeUnit.SECONDS);
    pluginService.stop("flowCliE");

    Plugin plugin = pluginDao.get("flowCliE");
    Assert.assertEquals(PluginStatus.PENDING, plugin.getStatus());
    Assert.assertEquals(false, plugin.getStopped());
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:20,代码来源:PluginServiceTest.java

示例12: main

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    builder.run(args);

    LOGGER.info("hi-log-log4j2 start successfully");

    String a = "哈哈";
    while (true) {
        LOGGER.info("i am test, {}", a);
        Thread.sleep(1000);
    }
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java

示例13: main

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("collector trace start successfully");

    KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer");
    Task task = (Task) context.getBean("rpcTraceTask");

    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task));
    task.doTask();
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java

示例14: main

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("collector indexer start successfully");

    KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer");
    Task task = (Task) context.getBean("indexerTask");

    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task));
    task.doTask();
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java

示例15: main

import org.springframework.context.ApplicationListener; //导入依赖的package包/类
public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class);
    Set<ApplicationListener<?>> listeners = builder.application().getListeners();
    for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) {
        ApplicationListener<?> listener = it.next();
        if (listener instanceof LoggingApplicationListener) {
            it.remove();
        }
    }
    builder.application().setListeners(listeners);
    ConfigurableApplicationContext context = builder.run(args);
    LOGGER.info("collector metrics start successfully");

    KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer");
    Task task = (Task) context.getBean("metricsTask");

    // 优雅停止项目
    Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task));
    task.doTask();
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:21,代码来源:Launcher.java


注:本文中的org.springframework.context.ApplicationListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。