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


Java ContextClosedEvent类代码示例

本文整理汇总了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.");
}
 
开发者ID:Netflix,项目名称:metacat,代码行数:22,代码来源:MetacatInitializationService.java

示例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();
    }
}
 
开发者ID:justice-code,项目名称:star-map,代码行数:18,代码来源:TaskExecutor.java

示例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());
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:19,代码来源:RuntimeExecBeansTest.java

示例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;
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:BlueprintContainerProcessor.java

示例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();
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:17,代码来源:AbstractContextCloseHandler.java

示例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();
        }
    }
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:19,代码来源:App.java

示例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();
            }
        }
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:27,代码来源:App.java

示例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();
    }
}
 
开发者ID:kevinKaiF,项目名称:cango,代码行数:25,代码来源:CangoManagerServiceImpl.java

示例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); }
    };
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:22,代码来源:BalancerConfiguration.java

示例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");
                }
            }
        });
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:17,代码来源:ApplicationThreadLocalCleaner.java

示例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();
	}
}
 
开发者ID:AvanzaBank,项目名称:astrix,代码行数:17,代码来源:AstrixFrameworkBean.java

示例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);

		}
	}
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:27,代码来源:MongoDbResource.java

示例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.");
    }
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:19,代码来源:DistributedLockWatcher.java


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