本文整理了Java中org.springframework.context.event.ApplicationContextEvent
类的一些代码示例,展示了ApplicationContextEvent
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ApplicationContextEvent
类的具体详情如下:
包路径:org.springframework.context.event.ApplicationContextEvent
类名称:ApplicationContextEvent
[英]Base class for events raised for an ApplicationContext.
[中]为ApplicationContext引发的事件的基类。
代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba
@Override
public void onApplicationEvent(T event) {
if (event instanceof ApplicationContextEvent) {
ApplicationContext applicationContext = ((ApplicationContextEvent) event)
.getApplicationContext();
// skip bootstrap context or super parent context.
if (applicationContext.getParent() == null
|| BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext
.getEnvironment().getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
return;
}
}
Class<?> clazz = getClass();
lockMap.putIfAbsent(clazz, new AtomicBoolean(false));
AtomicBoolean handled = lockMap.get(clazz);
// only execute once.
if (!handled.compareAndSet(false, true)) {
return;
}
if (conditionalOnClass() != null) {
try {
Class.forName(conditionalOnClass());
}
catch (ClassNotFoundException e) {
// ignored
return;
}
}
handleEvent(event);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Get the {@code ApplicationContext} that the event was raised for.
*/
public final ApplicationContext getApplicationContext() {
return (ApplicationContext) getSource();
}
代码示例来源:origin: com.opentable.components/otj-metrics-core
private String formatMessage() {
final String formatCause;
if (cause == null) {
formatCause = "initialized to unhealthy";
} else {
formatCause = cause.getClass().getSimpleName() + " @ " + Instant.ofEpochMilli(cause.getTimestamp());
}
return formatCause;
}
private HealthCheck.Result makeResult() {
代码示例来源:origin: spring-projects/spring-integration
@Override
public synchronized void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext context = event.getApplicationContext();
if (event instanceof ContextRefreshedEvent) {
boolean contextHasIdGenerator = context.getBeanNamesForType(IdGenerator.class).length > 0;
if (contextHasIdGenerator) {
if (this.setIdGenerator(context)) {
IdGeneratorConfigurer.generatorContextId.add(context.getId());
}
}
}
else if (event instanceof ContextClosedEvent) {
if (IdGeneratorConfigurer.generatorContextId.contains(context.getId())) {
if (IdGeneratorConfigurer.generatorContextId.size() == 1) {
this.unsetIdGenerator();
}
IdGeneratorConfigurer.generatorContextId.remove(context.getId());
}
}
}
代码示例来源:origin: org.springframework/spring-context
/**
* Get the {@code ApplicationContext} that the event was raised for.
*/
public final ApplicationContext getApplicationContext() {
return (ApplicationContext) getSource();
}
代码示例来源:origin: com.github.skjolber.mockito-rest-spring/core
public void onApplicationEvent(ApplicationContextEvent event) {
if(event instanceof ContextRefreshedEvent) {
// spring context has been started
ApplicationContext applicationContext = event.getApplicationContext();
for(Class<?> bean : mockTargetBeans) {
Object value = applicationContext.getBean(bean);
map.put(bean, value);
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
try {
// we only want to listen for context events of the main application
// context, not its children
if (event.getSource().equals(applicationContext)) {
if (event instanceof ContextRefreshedEvent && !isDeployed) {
// deploy the process application
afterPropertiesSet();
} else if (event instanceof ContextClosedEvent) {
// undeploy the process application
destroy();
} else {
// ignore
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: alien4cloud/alien4cloud
private void onApplicationContextEvent(ApplicationContextEvent e) {
if (e instanceof ContextStartedEvent) {
onContextStarted(e.getApplicationContext());
} else if (e instanceof ContextStoppedEvent) {
onContextStopped(e.getApplicationContext());
}
}
代码示例来源:origin: apache/servicemix-bundles
/**
* Get the {@code ApplicationContext} that the event was raised for.
*/
public final ApplicationContext getApplicationContext() {
return (ApplicationContext) getSource();
}
代码示例来源:origin: spheras/messic
@Override
public void onApplicationEvent( ApplicationContextEvent event )
{
ApplicationContext ac = event.getApplicationContext();
synchronized ( this )
{
if ( ac != null && !this.flagMessicInited )
{
this.flagMessicInited = true;
checkService();
}
}
}
代码示例来源:origin: spheras/messic
@Override
public void onApplicationEvent( ApplicationContextEvent arg0 )
{
ApplicationContext ac = arg0.getApplicationContext();
synchronized ( this )
{
if ( ac != null && !this.flagMessicInited )
{
this.flagMessicInited = true;
refreshServer();
}
}
}
代码示例来源:origin: OpenWiseSolutions/openhub-framework
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
Assert.notNull(event, "event must not be null");
ApplicationContext applicationContext = event.getApplicationContext();
//remove context from created registry
applicationContextsRegistry.remove(applicationContext);
//add new found contexts
if (event instanceof ContextRefreshedEvent || event instanceof ContextStartedEvent) {
LOG.info("Create new registry for context '{}.'", applicationContext.getDisplayName());
applicationContextsRegistry.put(applicationContext, new ApplicationContextRegistry(applicationContext));
}
}
代码示例来源:origin: shunyang/thrift-all
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext context = event.getApplicationContext();
if (event instanceof ContextRefreshedEvent|| event instanceof ContextStartedEvent){
initThriftServer(context);
logger.debug("Thrift Server 配置加载成功");
}
if (event instanceof ContextStoppedEvent || event instanceof ContextClosedEvent){
try {
proxyBeanLocal.destroy();
} catch (Exception e) {
logger.error("Thrift Server 关闭失败");
e.printStackTrace();
}
}
}
代码示例来源:origin: wanghongfei/gae
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
// 上下文初始化完成时启动vertx
if (event instanceof ContextRefreshedEvent) {
startHttpServer(event.getApplicationContext());
} else if (event instanceof ContextClosedEvent) {
// 上下文关闭时关闭vertx
IndexIncrementLoader loader = event.getApplicationContext().getBean(IndexIncrementLoader.class);
try {
vertx.close();
if (null != loader) {
loader.shutdown();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: org.eclipse.gemini.blueprint/gemini-blueprint-core
public void onApplicationEvent(ApplicationContextEvent event) {
// publish
if (event instanceof ContextRefreshedEvent) {
registerService(event.getApplicationContext());
} else if (event instanceof ContextClosedEvent) {
unregisterService();
}
}
代码示例来源:origin: com.dell.cpsd.common.messaging/common-rabbitmq
@Override
public void onApplicationEvent(ApplicationContextEvent event)
{
if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent || event instanceof ContextRefreshedEvent)
{
ApplicationContext context = event.getApplicationContext();
RegistrationNotifierService registrationNotifierService = context.getBean(RegistrationNotifierService.class);
if (registrationNotifierService == null)
{
return;
}
if (event instanceof ContextRefreshedEvent)
{
Map<String, MessageRegistrationAware> msgRegistrations = context.getBeansOfType(MessageRegistrationAware.class);
Map<String, Binding> bindings = context.getBeansOfType(Binding.class);
for (Map.Entry<String, MessageRegistrationAware> registration : msgRegistrations.entrySet())
{
MessageRegistrationAware messageRegistration = registration.getValue();
if (messageRegistration.isAutoRegister())
{
notify(registrationNotifierService, registration.getValue(), bindings.values());
}
}
}
else
{
withdraw(registrationNotifierService);
}
}
}
代码示例来源:origin: com.dell.cpsd/common-rabbitmq
@Override
public void onApplicationEvent(ApplicationContextEvent event)
{
if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent || event instanceof ContextRefreshedEvent)
{
ApplicationContext context = event.getApplicationContext();
RegistrationNotifierService registrationNotifierService = context.getBean(RegistrationNotifierService.class);
if (registrationNotifierService == null)
{
return;
}
if (event instanceof ContextRefreshedEvent)
{
Map<String, MessageRegistrationAware> msgRegistrations = context.getBeansOfType(MessageRegistrationAware.class);
Map<String, Binding> bindings = context.getBeansOfType(Binding.class);
for (Map.Entry<String, MessageRegistrationAware> registration : msgRegistrations.entrySet())
{
MessageRegistrationAware messageRegistration = registration.getValue();
if (messageRegistration.isAutoRegister())
{
notify(registrationNotifierService, registration.getValue(), bindings.values());
}
}
}
else
{
withdraw(registrationNotifierService);
}
}
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-alicloud-context
@Override
public void onApplicationEvent(T event) {
if (event instanceof ApplicationContextEvent) {
ApplicationContext applicationContext = ((ApplicationContextEvent) event)
.getApplicationContext();
// skip bootstrap context or super parent context.
if (applicationContext.getParent() == null
|| BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext
.getEnvironment().getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
return;
}
}
Class<?> clazz = getClass();
lockMap.putIfAbsent(clazz, new AtomicBoolean(false));
AtomicBoolean handled = lockMap.get(clazz);
// only execute once.
if (!handled.compareAndSet(false, true)) {
return;
}
if (conditionalOnClass() != null) {
try {
Class.forName(conditionalOnClass());
}
catch (ClassNotFoundException e) {
// ignored
return;
}
}
handleEvent(event);
}
代码示例来源:origin: org.springframework.integration/spring-integration-core
@Override
public synchronized void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext context = event.getApplicationContext();
if (event instanceof ContextRefreshedEvent) {
boolean contextHasIdGenerator = context.getBeanNamesForType(IdGenerator.class).length > 0;
if (contextHasIdGenerator) {
if (this.setIdGenerator(context)) {
IdGeneratorConfigurer.generatorContextId.add(context.getId());
}
}
}
else if (event instanceof ContextClosedEvent) {
if (IdGeneratorConfigurer.generatorContextId.contains(context.getId())) {
if (IdGeneratorConfigurer.generatorContextId.size() == 1) {
this.unsetIdGenerator();
}
IdGeneratorConfigurer.generatorContextId.remove(context.getId());
}
}
}
代码示例来源:origin: com.airlenet/play-integration-core
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
if (event instanceof ContextStartedEvent) {
ApplicationContext applicationContext = event.getApplicationContext();
if (applicationContext.getParent() == null) {// root 开始
System.out.println("Play Framework Starting...");
}
}
if (event instanceof ContextRefreshedEvent) {
ApplicationContext applicationContext = event.getApplicationContext();
if(lifeCycleListeners != null) {
AnnotationAwareOrderComparator.sort(lifeCycleListeners);
}
if (applicationContext.getParent() == null) {// root 启动完成
if (lifeCycleListeners != null) {
lifeCycleListeners.forEach(listener -> listener.onRootContextRefreshed());
}
} else {
if (lifeCycleListeners != null) {
lifeCycleListeners.forEach(listener -> listener.onServletContextRefreshed());
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!