當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。