本文整理匯總了Java中org.springframework.context.event.ContextClosedEvent類的典型用法代碼示例。如果您正苦於以下問題:Java ContextClosedEvent類的具體用法?Java ContextClosedEvent怎麽用?Java ContextClosedEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ContextClosedEvent類屬於org.springframework.context.event包,在下文中一共展示了ContextClosedEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: stop
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
/**
* Metacat service shutdown.
*
* @param event Event when the context is shutting down
*/
@EventListener
public void stop(final ContextClosedEvent event) {
log.info("Metacat application is stopped per {}. Stopping services.", event);
try {
this.pluginsLoaded.set(false);
this.connectorManager.stop();
this.catalogsLoaded.set(false);
this.threadServiceManager.stop();
this.metacatThriftService.stop();
this.thriftStarted.set(false);
} catch (final Exception e) {
// Just log it since we're shutting down anyway shouldn't matter to propagate it
log.error("Unable to properly shutdown services due to {}", e.getMessage(), e);
}
log.info("Finished stopping services.");
}
示例2: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event.getClass() == ContextRefreshedEvent.class) {
logger.info("register url: " + infoHolder.taskProtocolUrl());
extensionLoader.loadExtension(Registry.class).doRegister(infoHolder.taskProtocolUrl());
try {
extensionLoader.loadExtension(ProtocolFactory.class).server().openServer(infoHolder.taskProtocolUrl());
} catch (Exception e) {
throw new RuntimeException(e);
}
sandbox.configSandbox();
} else if (event.getClass() == ContextClosedEvent.class) {
logger.info("unregister url: " + infoHolder.taskProtocolUrl());
extensionLoader.loadExtension(Registry.class).unRegister(infoHolder.taskProtocolUrl());
extensionLoader.loadExtension(ProtocolFactory.class).server().close();
}
}
示例3: testBootstrapAndShutdown
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
public void testBootstrapAndShutdown() throws Exception
{
// now bring up the bootstrap
ApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
// the folder should be gone
assertFalse("Folder was not deleted by bootstrap", dir.exists());
// now create the folder again
dir.mkdir();
assertTrue("Directory not created", dir.exists());
// announce that the context is closing
ctx.publishEvent(new ContextClosedEvent(ctx));
// the folder should be gone
assertFalse("Folder was not deleted by shutdown", dir.exists());
}
示例4: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextClosedEvent) {
enabled = false;
return;
}
if (event instanceof ContextRefreshedEvent) {
initialized = true;
return;
}
if (event instanceof OsgiServiceDependencyWaitStartingEvent) {
if (enabled) {
OsgiServiceDependencyWaitStartingEvent evt = (OsgiServiceDependencyWaitStartingEvent) event;
String[] filter = new String[] { evt.getServiceDependency().getServiceFilter().toString() };
BlueprintEvent waitingEvent =
new BlueprintEvent(BlueprintEvent.WAITING, bundleContext.getBundle(), extenderBundle,
filter);
listenerManager.blueprintEvent(waitingEvent);
dispatcher.waiting(waitingEvent);
}
return;
}
}
示例5: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void onApplicationEvent(ContextClosedEvent event) {
for (String eventClassName : getSpringContext().getBeanNameByType(ContextEvent.class)) {
ContextEvent eventClass = (ContextEvent) getSpringContext().getBean(eventClassName);
if (eventClass == null) {
continue;
}
eventClass.stop();
LOGGER.trace("%s stopped", eventClassName);
}
getTaskExecutor().setWaitForTasksToCompleteOnShutdown(true);
getTaskExecutor().setAwaitTerminationSeconds(10);
getTaskExecutor().shutdown();
}
示例6: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void onApplicationEvent(ContextClosedEvent event) {
this.connector.pause();
Executor executor = this.connector.getProtocolHandler().getExecutor();
if (executor instanceof ThreadPoolExecutor) {
try {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
threadPoolExecutor.shutdown();
if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
log.warn("Tomcat thread pool did not shut down gracefully within "
+ "30 seconds. Proceeding with forceful shutdown");
}
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
示例7: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void onApplicationEvent(ContextClosedEvent event) {
log.info("Starting graceful shutdown of Tomcat");
if (this.connector != null)
{
this.connector.pause();
Executor executor = this.connector.getProtocolHandler().getExecutor();
if (executor instanceof ThreadPoolExecutor) {
try {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
threadPoolExecutor.shutdown();
if (!threadPoolExecutor.awaitTermination(20, TimeUnit.SECONDS)) {
log.warn("Tomcat thread pool did not shut down gracefully within "
+ "20 seconds. Proceeding with forceful shutdown");
}
else
{
log.info("Thread pool has closed");
}
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
}
示例8: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
// 容器啟動完成後裝載之前已添加的實例
if (applicationEvent instanceof ContextRefreshedEvent) {
LOGGER.info("spring container start all persisted cangoInstance!");
CangoInstances condition = new CangoInstances();
condition.setState(State.START.getCode());
List<CangoInstances> instancesList = cangoInstancesService.findByCondition(condition);
int countMysqlInstance = 0;
int countOracleInstance = 0;
if (!CollectionUtils.isEmpty(instancesList)) {
Map<String, Integer> countMap = internalStartCanalAndYuGong(instancesList, null);
countMysqlInstance = countMap.get(CANAL_INSTANCE);
countOracleInstance = countMap.get(ORACLE_INSTANCE);
}
LOGGER.info("spring container start all persisted cangoInstance successfully, count MysqlInstance number {}, OracleInstance number {}!",
countMysqlInstance, countOracleInstance);
}
if (applicationEvent instanceof ContextClosedEvent) {
shutdown();
}
}
示例9: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@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();
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:LoggingApplicationListener.java
示例10: closingChildContextDoesNotCleanUpLoggingSystem
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@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();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:LoggingApplicationListenerTests.java
示例11: applicationListener
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
/**
* Listens ContextClosedEvent and Closes all async http connections
*/
@Bean
ApplicationListener<?> applicationListener() {
return new SmartApplicationListener() {
@Override
public int getOrder() { return 0; }
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
return ContextClosedEvent.class.isAssignableFrom(eventType);
}
@Override
public boolean supportsSourceType(Class<?> sourceType) { return true; }
@Override
public void onApplicationEvent(ApplicationEvent event) { Closeables.close(proxyInstance); }
};
}
示例12: setApplicationContext
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// register a context close handler
if (applicationContext instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
context.addApplicationListener(new ApplicationListener<ContextClosedEvent>() {
@Override
public void onApplicationEvent(ContextClosedEvent e) {
LOG.info("Context '" + e.getApplicationContext().getDisplayName() + "' closed, removing registered ApplicationThreadLocals");
if (!ApplicationThreadLocal.clear()) {
LOG.error("Error(s) occurred removing registered ApplicationThreadLocals");
}
}
});
}
}
示例13: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@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();
}
}
示例14: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
public void onApplicationEvent(ApplicationEvent event) {
if(!doNothing) {
if (event instanceof ContextClosedEvent) {
m_executorService.shutdown();
try {
m_executorService.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
String error = CommonUtils.redirectPrintStackTraceToString(e);
if (LOGGER.isErrorEnabled())
LOGGER.error(
"Waiting for shutdown, got InterruptedException: "
+ error);
}
} else {
BeanFactoryUpdater updater = new BeanFactoryUpdater();
updater.setApplicationEvent(event);
// Submit to the Executor Service to execute this task.
m_executorService.submit(updater);
}
}
}
示例15: onApplicationEvent
import org.springframework.context.event.ContextClosedEvent; //導入依賴的package包/類
@Override
public void onApplicationEvent(ContextClosedEvent event) {
if (!locks.isEmpty()) {
LOGGER.info("Application is being shut down but {} locks remain, releasing them...", locks.size());
final Collection<DistributedLock> locksToRelease = new ArrayList<>(locks.values());
for (DistributedLock lock : locksToRelease) {
LOGGER.info("Releasing lock '{}'", lock.getKey());
try {
lock.unlock();
} catch (Exception e) {
LOGGER.warn("Unable to release lock '{}' due to exception.", e);
}
}
LOGGER.info("Locks released.");
} else {
LOGGER.info("No lock to release on shutdown.");
}
}