use of org.eclipse.scout.rt.platform.IPlatformListener in project scout.rt by eclipse.
the class PlatformImplementorTest method doTestAwaitPlatformStartedFailsInState.
protected void doTestAwaitPlatformStartedFailsInState(final State platformStartFailsInState) throws Exception {
// create platform listener that fails in given state
BeanMetaData bean = new BeanMetaData(IPlatformListener.class).withApplicationScoped(true).withInitialInstance(new IPlatformListener() {
@Override
public void stateChanged(PlatformEvent event) {
if (event.getState() == platformStartFailsInState) {
throw new TestingPlatformStartupException();
}
}
});
// create platform instance and start it in another thread
final TestingPlatformImplementor platform = new TestingPlatformImplementor(bean);
Future<?> platformStartFuture = startPlatformInAnotherThread(platform);
// current thread is expected to be suspended
assertAwaitPlatformStarted(platform, platformStartFailsInState == null);
// wait until platform starter has been finished and either expect no failures or the intended startup exception
if (platformStartFailsInState == null) {
platformStartFuture.get();
} else {
try {
platformStartFuture.get();
fail("Platform is not expected to be started");
} catch (ExecutionException e) {
assertSame(TestingPlatformStartupException.class, e.getCause().getClass());
}
}
// again awaitPlatformStartedFails
assertAwaitPlatformStarted(platform, platformStartFailsInState == null);
}
use of org.eclipse.scout.rt.platform.IPlatformListener in project scout.rt by eclipse.
the class PlatformImplementorTest method testAwaitPlatformStartedFailsInPlatformStopping.
@Test
public void testAwaitPlatformStartedFailsInPlatformStopping() throws Exception {
final CountDownLatch stoppingLatch = new CountDownLatch(1);
final CountDownLatch continueStoppingLatch = new CountDownLatch(1);
// crate platform listener that signals stopping state
BeanMetaData bean = new BeanMetaData(IPlatformListener.class).withApplicationScoped(true).withInitialInstance(new IPlatformListener() {
@Override
public void stateChanged(PlatformEvent event) {
if (event.getState() == State.PlatformStopping) {
stoppingLatch.countDown();
try {
continueStoppingLatch.await();
} catch (InterruptedException e) {
// nop
}
}
}
});
final TestingPlatformImplementor platform = new TestingPlatformImplementor(bean);
platform.start();
// expect platform started
platform.awaitPlatformStarted();
Future<?> platformStopFuture = s_executor.submit(new Runnable() {
@Override
public void run() {
platform.stop();
}
});
stoppingLatch.await();
try {
platform.awaitPlatformStarted();
} catch (PlatformException e) {
assertEquals("The platform is stopping.", e.getMessage());
}
continueStoppingLatch.countDown();
platformStopFuture.get();
}
use of org.eclipse.scout.rt.platform.IPlatformListener in project scout.rt by eclipse.
the class PlatformImplementor method fireStateEvent.
@SuppressWarnings("squid:S1181")
protected void fireStateEvent(State newState) {
if (m_beanManager == null) {
// can happen if there is an error creating the bean manager. cannot move to status invalid. just do nothing.
return;
}
PlatformEvent event = new PlatformEvent(this, newState);
try {
for (IBean<IPlatformListener> bean : m_beanManager.getBeans(IPlatformListener.class)) {
IPlatformListener listener = bean.getInstance();
listener.stateChanged(event);
}
} catch (RuntimeException | Error e) {
LOG.error("Error during event listener notification.", e);
changeState(State.PlatformInvalid, true);
throw e;
}
}
Aggregations