List of usage examples for org.springframework.context.event ContextRefreshedEvent ContextRefreshedEvent
public ContextRefreshedEvent(ApplicationContext source)
From source file:org.springframework.context.support.AbstractApplicationContext.java
/** * Finish the refresh of this context, invoking the LifecycleProcessor's * onRefresh() method and publishing the * {@link org.springframework.context.event.ContextRefreshedEvent}. *//*from www . j ava 2 s .c o m*/ protected void finishRefresh() { // Clear context-level resource caches (such as ASM metadata from scanning). clearResourceCaches(); // Initialize lifecycle processor for this context. initLifecycleProcessor(); // Propagate refresh to lifecycle processor first. getLifecycleProcessor().onRefresh(); // Publish the final event. publishEvent(new ContextRefreshedEvent(this)); // Participate in LiveBeansView MBean, if active. LiveBeansView.registerApplicationContext(this); }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java
@Test public void testOnApplicationEvent() { TestApplicationListener testApplicationListener = new TestApplicationListener("testOnApplicationEvent"); try {//from www. j a v a 2s . c o m testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener); assertUnnotified(testApplicationListener); ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent( mock(ApplicationContext.class, "testOnApplicationEvent")); new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent); assertNotified(testApplicationListener, testContextRefreshedEvent); } finally { SpringContextBootstrappingInitializer.unregister(testApplicationListener); } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java
@Test public void testOnApplicationEventWithMultipleRegisteredApplicationListeners() { TestApplicationListener testApplicationListenerOne = new TestApplicationListener( "testOnApplicationEventWithMultipleRegisteredApplicationListeners.1"); TestApplicationListener testApplicationListenerTwo = new TestApplicationListener( "testOnApplicationEventWithMultipleRegisteredApplicationListeners.2"); TestApplicationListener testApplicationListenerThree = new TestApplicationListener( "testOnApplicationEventWithMultipleRegisteredApplicationListeners.3"); try {//w ww .j ava2s . c o m testApplicationListenerOne = SpringContextBootstrappingInitializer.register(testApplicationListenerOne); testApplicationListenerTwo = SpringContextBootstrappingInitializer.register(testApplicationListenerTwo); testApplicationListenerThree = SpringContextBootstrappingInitializer .register(testApplicationListenerThree); assertUnnotified(testApplicationListenerOne); assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mock( ApplicationContext.class, "testOnApplicationEventWithMultipleRegisteredApplicationListeners")); new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent); assertNotified(testApplicationListenerOne, testContextRefreshedEvent); assertNotified(testApplicationListenerTwo, testContextRefreshedEvent); assertNotified(testApplicationListenerThree, testContextRefreshedEvent); } finally { SpringContextBootstrappingInitializer.unregister(testApplicationListenerOne); SpringContextBootstrappingInitializer.unregister(testApplicationListenerTwo); SpringContextBootstrappingInitializer.unregister(testApplicationListenerThree); } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java
@Test public void testOnApplicationEventWithUnregisteredApplicationListener() { TestApplicationListener testApplicationListener = new TestApplicationListener( "testOnApplicationEventWithUnregisteredApplicationListener"); try {// w w w. j a v a 2s . c om testApplicationListener = SpringContextBootstrappingInitializer .unregister(SpringContextBootstrappingInitializer.register(testApplicationListener)); assertUnnotified(testApplicationListener); ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent( mock(ApplicationContext.class, "testRegisterThenUnregisterWithOnApplicationEvent")); new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent); assertUnnotified(testApplicationListener); } finally { SpringContextBootstrappingInitializer.unregister(testApplicationListener); } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java
@Test public void testNotifyOnExistingContextRefreshedEventAfterContextRefreshed() { ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mock(ApplicationContext.class)); new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent); TestApplicationListener testApplicationListener = new TestApplicationListener( "testNotifyOnExistingContextRefreshedEventAfterContextRefreshed"); try {//from ww w. j av a 2 s . com testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener); assertNotified(testApplicationListener, testContextRefreshedEvent); } finally { SpringContextBootstrappingInitializer.unregister(testApplicationListener); } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java
@Test public void testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent() { ConfigurableApplicationContext mockApplicationContext = mock(ConfigurableApplicationContext.class, "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent"); SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer(); TestApplicationListener testApplicationListenerOne = new TestApplicationListener( "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.1"); TestApplicationListener testApplicationListenerTwo = new TestApplicationListener( "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.2"); TestApplicationListener testApplicationListenerThree = new TestApplicationListener( "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.3"); try {/*from w w w . ja va 2 s . co m*/ testApplicationListenerOne = SpringContextBootstrappingInitializer.register(testApplicationListenerOne); assertUnnotified(testApplicationListenerOne); assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mockApplicationContext); initializer.onApplicationEvent(testContextRefreshedEvent); assertNotified(testApplicationListenerOne, testContextRefreshedEvent); assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); testApplicationListenerTwo = SpringContextBootstrappingInitializer.register(testApplicationListenerTwo); assertNotified(testApplicationListenerTwo, testContextRefreshedEvent); assertUnnotified(testApplicationListenerOne); assertUnnotified(testApplicationListenerThree); ContextStoppedEvent testContextStoppedEvent = new ContextStoppedEvent(mockApplicationContext); initializer.onApplicationEvent(testContextStoppedEvent); assertUnnotified(testApplicationListenerOne); assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); initializer.onApplicationEvent(testContextRefreshedEvent); assertNotified(testApplicationListenerOne, testContextRefreshedEvent); assertNotified(testApplicationListenerTwo, testContextRefreshedEvent); assertUnnotified(testApplicationListenerThree); ContextClosedEvent testContextClosedEvent = new ContextClosedEvent(mockApplicationContext); initializer.onApplicationEvent(testContextClosedEvent); assertUnnotified(testApplicationListenerOne); assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); SpringContextBootstrappingInitializer.register(testApplicationListenerThree); assertUnnotified(testApplicationListenerOne); assertUnnotified(testApplicationListenerTwo); assertUnnotified(testApplicationListenerThree); } finally { SpringContextBootstrappingInitializer.unregister(testApplicationListenerOne); SpringContextBootstrappingInitializer.unregister(testApplicationListenerTwo); SpringContextBootstrappingInitializer.unregister(testApplicationListenerThree); } }