List of usage examples for org.springframework.context.support GenericApplicationContext addApplicationListener
@Override public void addApplicationListener(ApplicationListener<?> listener)
From source file:edu.internet2.middleware.shibboleth.common.util.EventingMapBasedStorageServiceTest.java
public void testStorageService() { AddEntryListener addListener = new AddEntryListener(); RemoveEntryListener removeListener = new RemoveEntryListener(); GenericApplicationContext appCtx = new GenericApplicationContext(); EventingMapBasedStorageService<String, String> storageService = new EventingMapBasedStorageService<String, String>(); storageService.setApplicationContext(appCtx); appCtx.addApplicationListener(addListener); appCtx.addApplicationListener(removeListener); appCtx.refresh();//from w w w . j av a2 s .c o m String partition = "partition"; String value = "value"; String key1 = "string1"; storageService.put(partition, key1, value); String key2 = "string2"; storageService.put(partition, key2, value); String key3 = "string3"; storageService.put(partition, key3, value); String key4 = "string4"; storageService.put(partition, key4, value); String key5 = "string5"; storageService.put(partition, key5, value); assertEquals(5, addListener.getCount()); assertEquals(0, removeListener.getCount()); assertEquals(true, storageService.contains(partition, key1)); assertEquals(true, storageService.contains(partition, key2)); assertEquals(true, storageService.contains(partition, key3)); assertEquals(true, storageService.contains(partition, key4)); assertEquals(true, storageService.contains(partition, key5)); storageService.remove(partition, key1); assertEquals(5, addListener.getCount()); assertEquals(1, removeListener.getCount()); assertEquals(false, storageService.contains(partition, key1)); assertEquals(true, storageService.contains(partition, key2)); assertEquals(true, storageService.contains(partition, key3)); assertEquals(true, storageService.contains(partition, key4)); assertEquals(true, storageService.contains(partition, key5)); Iterator<String> keysItr = storageService.getKeys(partition); keysItr.next(); keysItr.remove(); assertEquals(5, addListener.getCount()); assertEquals(2, removeListener.getCount()); Iterator<String> partiationsItr = storageService.getPartitions(); partiationsItr.next(); partiationsItr.remove(); assertEquals(5, addListener.getCount()); assertEquals(5, removeListener.getCount()); assertEquals(false, storageService.contains(partition, key1)); assertEquals(false, storageService.contains(partition, key2)); assertEquals(false, storageService.contains(partition, key3)); assertEquals(false, storageService.contains(partition, key4)); assertEquals(false, storageService.contains(partition, key5)); }
From source file:com.obergner.hzserver.Main.java
void start() throws Exception { enableHangupSupport();/*from ww w .j ava 2s.c om*/ this.serverInfo.logBootStart(); final GenericApplicationContext ctx = new GenericApplicationContext(); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); xmlReader.loadBeanDefinitions("classpath:META-INF/spring/hz-server-main-context.xml", "classpath*:META-INF/spring/hz-cache-context.xml"); ctx.registerShutdownHook(); ctx.addApplicationListener(new ApplicationListener<ContextRefreshedEvent>() { @Override public void onApplicationEvent(final ContextRefreshedEvent event) { Main.this.serverInfo.logBootCompleted(); } }); ctx.addApplicationListener(new ApplicationListener<ContextStoppedEvent>() { @Override public void onApplicationEvent(final ContextStoppedEvent event) { Main.this.serverInfo.logShutdownCompleted(); } }); ctx.refresh(); }
From source file:org.springframework.cloud.function.web.function.FunctionEndpointInitializer.java
private void registerWebFluxAutoConfiguration(GenericApplicationContext context) { context.registerBean(DefaultErrorWebExceptionHandler.class, () -> errorHandler(context)); context.registerBean(WebHttpHandlerBuilder.WEB_HANDLER_BEAN_NAME, HttpWebHandlerAdapter.class, () -> httpHandler(context)); context.addApplicationListener(new ServerListener(context)); }