use of org.springframework.context.event.ContextClosedEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method closingChildContextDoesNotCleanUpLoggingSystem.
@Test
void closingChildContextDoesNotCleanUpLoggingSystem() {
System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
multicastEvent(new ApplicationStartingEvent(this.bootstrapContext, 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);
multicastEvent(new ContextClosedEvent(childContext));
assertThat(loggingSystem.cleanedUp).isFalse();
multicastEvent(new ContextClosedEvent(this.context));
assertThat(loggingSystem.cleanedUp).isTrue();
childContext.close();
}
use of org.springframework.context.event.ContextClosedEvent in project spring-boot by spring-projects.
the class LoggingApplicationListenerTests method bridgeHandlerLifecycle.
@Test
void bridgeHandlerLifecycle() {
assertThat(bridgeHandlerInstalled()).isTrue();
multicastEvent(new ContextClosedEvent(this.context));
assertThat(bridgeHandlerInstalled()).isFalse();
}
use of org.springframework.context.event.ContextClosedEvent in project tomee by apache.
the class SpringBus method onApplicationEvent.
public void onApplicationEvent(ApplicationEvent event) {
if (ctx == null) {
return;
}
boolean doIt = false;
ApplicationContext ac = ctx;
while (ac != null) {
if (event.getSource() == ac) {
doIt = true;
break;
}
ac = ac.getParent();
}
if (doIt) {
if (event instanceof ContextRefreshedEvent) {
if (getState() != BusState.RUNNING) {
initialize();
}
} else if (event instanceof ContextClosedEvent && getState() == BusState.RUNNING) {
// The bus could be create by using SpringBusFactory.createBus("/cxf.xml");
// Just to make sure the shutdown is called rightly
shutdown();
}
}
}
use of org.springframework.context.event.ContextClosedEvent in project alfresco-repository by Alfresco.
the class SafeApplicationEventMulticaster method multicastEvent.
@Override
public void multicastEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent && event.getSource() == this.appContext) {
this.isApplicationStarted = true;
for (ApplicationEvent queuedEvent : this.queuedEvents) {
multicastEventInternal(queuedEvent);
}
this.queuedEvents.clear();
multicastEventInternal(event);
} else if (event instanceof ContextClosedEvent && event.getSource() == this.appContext) {
this.isApplicationStarted = false;
multicastEventInternal(event);
} else if (this.isApplicationStarted) {
multicastEventInternal(event);
} else {
this.queuedEvents.add(event);
}
}
use of org.springframework.context.event.ContextClosedEvent in project data-prep by Talend.
the class DistributedLockWatcherTest method shouldReleaseOnClose.
@Test
public void shouldReleaseOnClose() throws Exception {
// given
final LockFactory delegate = mock(LockFactory.class);
final DistributedLock mock1 = mock(DistributedLock.class);
when(mock1.getKey()).thenReturn("1234");
final DistributedLock mock2 = mock(DistributedLock.class);
when(mock2.getKey()).thenReturn("5678");
when(delegate.getLock(eq("1234"))).thenReturn(mock1);
when(delegate.getLock(eq("5678"))).thenReturn(mock2);
doAnswer(invocation -> {
// on purpose unchecked exception
throw new RuntimeException();
}).when(mock2).unlock();
final DistributedLockWatcher watcher = new DistributedLockWatcher(delegate);
watcher.getLock("1234");
watcher.getLock("5678");
// when
watcher.onApplicationEvent(new ContextClosedEvent(new AnnotationConfigApplicationContext()));
// then
verify(mock1, times(1)).unlock();
verify(mock2, times(1)).unlock();
assertEquals(0, watcher.getLocks().size());
}
Aggregations