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


Java ApplicationContextEvent类代码示例

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


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

示例1: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的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

示例2: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
  try {

    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);
  }
}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:19,代码来源:SpringProcessApplication.java

示例3: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
    if (event instanceof ContextClosedEvent || event instanceof ContextStoppedEvent) {
        List<Entity> everyone = entityRepository.findByXIsNotNullAndYIsNotNullAndZIsNotNull();
        GameOutput output = new GameOutput("[red]EmergentMUD is shutting down. Please check back later!");

        entityService.sendMessageToListeners(everyone, output);
    }
}
 
开发者ID:scionaltera,项目名称:emergentmud,代码行数:10,代码来源:GameShutdownListener.java

示例4: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
public void onApplicationEvent(ApplicationContextEvent event) {
	// publish
	if (event instanceof ContextRefreshedEvent) {
		registerService(event.getApplicationContext());
	} else if (event instanceof ContextClosedEvent) {
		unregisterService();
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:9,代码来源:BlueprintContainerServicePublisher.java

示例5: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public final void onApplicationEvent(final ApplicationContextEvent event) {
    try {
        final ApplicationContext context = event.getApplicationContext();
        if (context instanceof XmlWebApplicationContext) {
            final XmlWebApplicationContext ctx = (XmlWebApplicationContext) context;
            String webContextName = ctx.getServletContext().getServletContextName();
            if (webContextName.contains("/")) {
                webContextName = webContextName.substring(webContextName.indexOf('/'));
            }
            ctx.setDisplayName(webContextName);
            MDC.put(LeveringVeld.MDC_APPLICATIE_NAAM, webContextName).close();
        }
        LOGGER.debug("Context event '{}'; id='{}', displayName='{}'", event.getClass().getSimpleName(), event
                .getApplicationContext().getId(), event.getApplicationContext().getDisplayName());

        if (event instanceof ContextClosedEvent) {
            LOGGER.info("==> Context voor applicatie '{}' is gestopt", event.getApplicationContext().getId());
        }
        /* Wanneer een applicatie is gestart, dan wordt een ContextRefreshedEvent gestuurt **/
        if (event instanceof ContextRefreshedEvent) {
            LOGGER.info("==> Context voor applicatie '{}' is gestart/herstart", event.getApplicationContext()
                    .getId());
            logJvmSettings();
        }
    } catch (final ApplicationContextException ex) {
        LOGGER.error("Fout bij het opstarten van de applicatiecontext bij event {}", event.toString(), ex);
    }


}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:32,代码来源:BrpApplicatieStartListener.java

示例6: contextRefreshed

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Test
public void contextRefreshed() throws Exception {
    Assert.assertEquals(2, contextRefreshedList.size());
    for (int i = 0; i < contextRefreshedList.size(); i++)
        Assert.assertEquals(i + 1, numeric.toInt(contextRefreshedList.get(i)));

    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
        Assert.assertEquals(4 + i * 2, contextRefreshedList.size());
        for (int j = 0; j < contextRefreshedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
    }

    Field field = ContainerImpl.class.getDeclaredField("refreshedListeners");
    field.setAccessible(true);
    Object object = field.get(container);
    field.set(container, Optional.empty());
    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
        Assert.assertEquals(6, contextRefreshedList.size());
        for (int j = 0; j < contextRefreshedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
    }

    ((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
    });
    Assert.assertEquals(6, contextRefreshedList.size());
    for (int i = 0; i < contextRefreshedList.size(); i++)
        Assert.assertEquals(i % 2 + 1, numeric.toInt(contextRefreshedList.get(i)));

    field.set(container, object);
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:33,代码来源:ContainerTest.java

示例7: contextClosed

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Test
public void contextClosed() throws Exception {
    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
        Assert.assertEquals(2 + i * 2, contextClosedList.size());
        for (int j = 0; j < contextRefreshedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
    }

    Field field = ContainerImpl.class.getDeclaredField("closedListeners");
    field.setAccessible(true);
    Object object = field.get(container);
    field.set(container, Optional.empty());
    for (int i = 0; i < 2; i++) {
        ((ContainerImpl) container).onApplicationEvent(new ContextClosedEvent(getApplicationContext()));
        Assert.assertEquals(4, contextClosedList.size());
        for (int j = 0; j < contextClosedList.size(); j++)
            Assert.assertEquals(j % 2 + 1, numeric.toInt(contextClosedList.get(j)));
    }

    ((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
    });
    Assert.assertEquals(4, contextClosedList.size());
    for (int i = 0; i < contextClosedList.size(); i++)
        Assert.assertEquals(i % 2 + 1, numeric.toInt(contextClosedList.get(i)));

    field.set(container, object);
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:29,代码来源:ContainerTest.java

示例8: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
protected void onApplicationEvent(ApplicationEvent event) {
	ConfigurableApplicationContext initializerApplicationContext = AutoConfigurationReportLoggingInitializer.this.applicationContext;
	if (event instanceof ContextRefreshedEvent) {
		if (((ApplicationContextEvent) event)
				.getApplicationContext() == initializerApplicationContext) {
			logAutoConfigurationReport();
		}
	}
	else if (event instanceof ApplicationFailedEvent) {
		if (((ApplicationFailedEvent) event)
				.getApplicationContext() == initializerApplicationContext) {
			logAutoConfigurationReport(true);
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:AutoConfigurationReportLoggingInitializer.java

示例9: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
	if(event.getApplicationContext()==appCtx) {
		if(event instanceof ContextRefreshedEvent) {
			start();
		} else if(event instanceof ContextStoppedEvent) {
			stop();
		}
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:15,代码来源:MetricRouterBuilder.java

示例10: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {		
	if(event.getApplicationContext()==appCtx) {
		if(event instanceof ContextRefreshedEvent) {
			try {
				start();
			} catch (Exception ex) {
				throw new RuntimeException(ex);
			}
		} else if(event instanceof ContextClosedEvent) {
			stop();
		}
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:19,代码来源:HttpJsonMetricForwarder.java

示例11: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
	if (event instanceof ContextRefreshedEvent && event.getApplicationContext().getParent() == null) {
		startMuleContext(event.getApplicationContext());
	} else if (event instanceof ContextClosedEvent) {
		stopMuleContext();
	}
}
 
开发者ID:denschu,项目名称:mule-spring-boot-starter,代码行数:9,代码来源:MuleContextInitializer.java

示例12: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
public void onApplicationEvent(ApplicationEvent event) {
  if (event instanceof ContextRefreshedEvent || event instanceof ContextBeanChangedEvent) {
    ApplicationContext context = ((ApplicationContextEvent) event).getApplicationContext();
    boolean hasInboundChannels = !context.getBeansOfType(InboundChannel.class).isEmpty();
    int flowControls = context.getBeansOfType(PipelineFlowControl.class).size();
    // Ignore this, but if there are others, register for management
    if (hasInboundChannels || flowControls > 1) {
      Management.removeBeanOrFolder(getBeanName(), this);
      Management.addBean(getBeanName(), this);
    }
  }
}
 
开发者ID:pulsarIO,项目名称:jetstream,代码行数:13,代码来源:ChannelFlowManagement.java

示例13: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent arg0) {

    if (arg0 instanceof ContextRefreshedEvent) {
        LOG.warn("READY: " + this.version);
    } else if (arg0 instanceof ContextClosedEvent) {
        LOG.warn("SHUTDOWN: " + this.version);
    }
}
 
开发者ID:efekahraman,项目名称:dynamise,代码行数:10,代码来源:AppListener.java

示例14: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationContextEvent event) {
	ApplicationContext ctx = event.getApplicationContext();
	if(!(ctx instanceof AnnotationConfigWebApplicationContext))
		throw new RuntimeException("Initialization of the apllication-context failed!");
	
	try {
		FileSystemUtil fsu = ctx.getBean(FileSystemUtil.class);
		fsu.init();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	
	logger.info("*** Application-context successful initialized");
}
 
开发者ID:th-schwarz,项目名称:bacoma,代码行数:16,代码来源:ApplicationContextListener.java

示例15: onApplicationEvent

import org.springframework.context.event.ApplicationContextEvent; //导入依赖的package包/类
/**
 * Listens for application lifecycle events (specifically start/stop),
 * and schedules the new run/cancels the next run as appropriate.
 * 
 * @param event the application event to process.
 */
@Override
public void onApplicationEvent(final ApplicationContextEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        this.applicationContext = event.getApplicationContext();
        this.startTimer();
    } else if (event instanceof ContextClosedEvent) {
        this.cancel();
        this.applicationContext = null;
        
        // This manually deregisters JDBC driver, which prevents Tomcat 7
        // from complaining about memory leaks from this class
        // XXX: Disabled as it's dangerous and Tomcat handles this much
        // better, even if it does complain
        /* Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            final Driver driver = drivers.nextElement();
            
            // Really ought to take the list of drivers to de-register from
            // application context
            if (driver instanceof com.microsoft.sqlserver.jdbc.SQLServerDriver) {
                try {
                    DriverManager.deregisterDriver(driver);
                } catch (SQLException e) {
                    log.error(String.format("Error deregistering driver %s", driver), e);
                }
            }
        } */
    }
}
 
开发者ID:rnicoll,项目名称:learn_syllabus_plus_sync,代码行数:36,代码来源:ScheduledJobManager.java


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