use of org.pentaho.platform.api.engine.IPentahoSystemListener in project pentaho-platform by pentaho.
the class PentahoSystem method shutdown.
public static void shutdown() {
serverStatusProvider.setStatus(IServerStatusProvider.ServerStatus.STOPPING);
if (LocaleHelper.getLocale() == null) {
LocaleHelper.setLocale(Locale.getDefault());
}
if (debug) {
// $NON-NLS-1$
Logger.debug(PentahoSystem.class, "Shutdown Listeners");
}
if (PentahoSystem.listeners != null) {
ListIterator<IPentahoSystemListener> systemListenerIterator = PentahoSystem.listeners.listIterator(PentahoSystem.listeners.size());
while (systemListenerIterator.hasPrevious()) {
IPentahoSystemListener listener = systemListenerIterator.previous();
if (listener != null) {
if (debug) {
// $NON-NLS-1$
Logger.debug(PentahoSystem.class, "Shutdown Listener: " + listener.getClass().getName());
}
try {
listener.shutdown();
} catch (Throwable e) {
Logger.error(PentahoSystem.class.getName(), Messages.getInstance().getErrorString("PentahoSystem.ERROR_0015_SHUTDOWN_FAILURE", listener.getClass().getName()), // $NON-NLS-1$
e);
}
}
}
}
if (debug) {
// $NON-NLS-1$
Logger.debug(PentahoSystem.class, "Listeners Shut Down");
}
clearObjectFactory();
systemExitPoint();
setApplicationContext(null);
PentahoSystem.initializedStatus = PentahoSystem.SYSTEM_NOT_INITIALIZED;
serverStatusProvider.setStatus(IServerStatusProvider.ServerStatus.DOWN);
}
use of org.pentaho.platform.api.engine.IPentahoSystemListener in project pentaho-platform by pentaho.
the class PluginAdapterIT method testPluginAdapterAsSystemListener.
@SuppressWarnings("cast")
@Test
public void testPluginAdapterAsSystemListener() throws Exception {
IPentahoSystemListener listener = (IPentahoSystemListener) pluginAdapter;
assertTrue(listener.startup(session));
// this does not do anything but it shouldn't error
listener.shutdown();
}
use of org.pentaho.platform.api.engine.IPentahoSystemListener in project pentaho-platform by pentaho.
the class PluginManagerNotConfiguredIT method testPluginAdapterViaSystemListenerAPI.
@SuppressWarnings("cast")
public void testPluginAdapterViaSystemListenerAPI() throws Exception {
startTest();
// $NON-NLS-1$
IPentahoSession session = new StandaloneSession("test user");
PluginAdapter mgr = new PluginAdapter();
assertTrue(mgr instanceof IPentahoSystemListener);
IPentahoSystemListener listener = (IPentahoSystemListener) mgr;
assertFalse(listener.startup(session));
// this does not do anything but it shouldn't error
listener.shutdown();
finishTest();
}
use of org.pentaho.platform.api.engine.IPentahoSystemListener in project pentaho-platform by pentaho.
the class BootTest method testObjectFactoryAvailableThruShutdown.
@Test
public void testObjectFactoryAvailableThruShutdown() {
final AtomicBoolean objectFactoryWasValid = new AtomicBoolean(false);
IPentahoSystemListener listener = new IPentahoSystemListener() {
@Override
public boolean startup(IPentahoSession session) {
return true;
}
@Override
public void shutdown() {
// Verify that the ObjectFactory is still valid at this point
String s = PentahoSystem.get(String.class);
// Not possible to assert within here as PentahoSystem catches all Exceptions, setting marker boolean instead.
objectFactoryWasValid.set("Testing".equals(s));
}
};
PentahoSystem.setSystemListeners(Collections.singletonList(listener));
PentahoSystem.init();
// Add an object to PentahoSystem, then verify that it can be retrieved
PentahoSystem.registerObject("Testing");
String s = PentahoSystem.get(String.class);
assertEquals("Testing", s);
PentahoSystem.shutdown();
// At this point the shutdown() method on the listener has been called, check the boolean flag.
assertTrue("ShutdownListener wasn't able to get object from PentahoSystem", objectFactoryWasValid.get());
}
use of org.pentaho.platform.api.engine.IPentahoSystemListener in project pentaho-platform by pentaho.
the class BootTest method testBootListeners.
@Test
public void testBootListeners() throws Exception {
PentahoSystemBoot boot = new PentahoSystemBoot();
boot.setFilePath("src/test/resources/solution");
boot.define(ISolutionEngine.class.getSimpleName(), Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
TestLifecycleListener lifecycleListener1 = new TestLifecycleListener();
TestLifecycleListener lifecycleListener2 = new TestLifecycleListener();
boot.addLifecycleListener(lifecycleListener1);
List<IPentahoSystemListener> lifecycleListeners1 = boot.getLifecycleListeners();
assertEquals(1, lifecycleListeners1.size());
assertEquals(lifecycleListener1, lifecycleListeners1.get(0));
assertFalse(TestLifecycleListener.startupCalled);
assertFalse(TestLifecycleListener.shutdownCalled);
List<IPentahoSystemListener> lifecycleListeners2 = new ArrayList<IPentahoSystemListener>();
lifecycleListeners2.add(lifecycleListener2);
boot.setLifecycleListeners(lifecycleListeners2);
List<IPentahoSystemListener> lifecycleListeners3 = boot.getLifecycleListeners();
assertEquals(1, lifecycleListeners3.size());
assertEquals(lifecycleListener2, lifecycleListeners3.get(0));
assertEquals(lifecycleListeners2, lifecycleListeners3);
IPentahoObjectFactory factory = boot.getFactory();
assertNotNull("object factory is null", factory);
assertTrue("object factory not definable", factory instanceof IPentahoDefinableObjectFactory);
assertFalse(boot.isInitialized());
boolean ok = boot.start();
assertNull(boot.getSettingsProvider());
assertTrue(boot.isInitialized());
assertTrue(ok);
assertTrue(TestLifecycleListener.startupCalled);
assertFalse(TestLifecycleListener.shutdownCalled);
boot.stop();
assertFalse(boot.isInitialized());
assertTrue(TestLifecycleListener.startupCalled);
assertTrue(TestLifecycleListener.shutdownCalled);
}
Aggregations