Search in sources :

Example 1 with IPentahoSystemListener

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);
}
Also used : IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener)

Example 2 with IPentahoSystemListener

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();
}
Also used : IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) Test(org.junit.Test)

Example 3 with IPentahoSystemListener

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();
}
Also used : PluginAdapter(org.pentaho.platform.plugin.services.pluginmgr.PluginAdapter) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 4 with IPentahoSystemListener

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Example 5 with IPentahoSystemListener

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);
}
Also used : PentahoSystemBoot(org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot) IPentahoDefinableObjectFactory(org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

IPentahoSystemListener (org.pentaho.platform.api.engine.IPentahoSystemListener)6 Test (org.junit.Test)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IPentahoDefinableObjectFactory (org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory)1 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)1 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1 PentahoSystemBoot (org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot)1 ChartBeansSystemListener (org.pentaho.platform.plugin.action.chartbeans.ChartBeansSystemListener)1 PluginAdapter (org.pentaho.platform.plugin.services.pluginmgr.PluginAdapter)1