Search in sources :

Example 26 with BundleEvent

use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testClassCircularityError.

public void testClassCircularityError() throws Exception {
    // $NON-NLS-1$
    Bundle circularityTest = installer.installBundle("circularity.test");
    // $NON-NLS-1$
    Bundle circularityTestA = installer.installBundle("circularity.test.a");
    // $NON-NLS-1$
    circularityTest.loadClass("circularity.test.TestCircularity");
    Object[] expectedEvents = new Object[2];
    expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, circularityTest);
    expectedEvents[1] = new BundleEvent(BundleEvent.STARTED, circularityTestA);
    Object[] actualEvents = simpleResults.getResults(2);
    compareResults(expectedEvents, actualEvents);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent)

Example 27 with BundleEvent

use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug300692_02.

public void testBug300692_02() throws BundleException {
    // $NON-NLS-1$
    Bundle chainTest = installer.installBundle("chain.test");
    // $NON-NLS-1$
    Bundle chainTestA = installer.installBundle("chain.test.a");
    // $NON-NLS-1$
    Bundle chainTestB = installer.installBundle("chain.test.b");
    // $NON-NLS-1$
    Bundle chainTestC = installer.installBundle("chain.test.c");
    // $NON-NLS-1$
    Bundle chainTestD = installer.installBundle("chain.test.d");
    syncListenerResults.getResults(0);
    StartLevel sl = installer.getStartLevel();
    int currentSL = sl.getStartLevel();
    int testSL = currentSL + 1;
    sl.setBundleStartLevel(chainTest, testSL);
    sl.setBundleStartLevel(chainTestA, testSL);
    sl.setBundleStartLevel(chainTestB, testSL);
    sl.setBundleStartLevel(chainTestC, testSL);
    sl.setBundleStartLevel(chainTestD, testSL);
    installer.resolveBundles(new Bundle[] { chainTest, chainTestA, chainTestB, chainTestC, chainTestD });
    Object[] expectedEvents = new Object[5];
    expectedEvents[0] = new BundleEvent(BundleEvent.RESOLVED, chainTestD);
    expectedEvents[1] = new BundleEvent(BundleEvent.RESOLVED, chainTestC);
    expectedEvents[2] = new BundleEvent(BundleEvent.RESOLVED, chainTestB);
    expectedEvents[3] = new BundleEvent(BundleEvent.RESOLVED, chainTestA);
    expectedEvents[4] = new BundleEvent(BundleEvent.RESOLVED, chainTest);
    Object[] actualEvents = syncListenerResults.getResults(5);
    compareResults(expectedEvents, actualEvents);
    try {
        System.setProperty("test.bug300692", "true");
        System.setProperty("test.bug300692.listener", "true");
        chainTest.start();
        sl.setStartLevel(testSL);
        Object[] expectedFrameworkEvents = new Object[1];
        expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
        Object[] actualFrameworkEvents = frameworkListenerResults.getResults(1);
        compareResults(expectedFrameworkEvents, actualFrameworkEvents);
        expectedEvents = new Object[14];
        int i = 0;
        expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestA);
        expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestB);
        expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestC);
        expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestD);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTest);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestD);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestD);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestB);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestB);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestC);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestC);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestA);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestA);
        expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTest);
        actualFrameworkEvents = syncListenerResults.getResults(14);
        compareResults(expectedEvents, actualFrameworkEvents);
    } finally {
        System.getProperties().remove("test.bug300692");
        System.getProperties().remove("test.bug300692.listener");
        sl.setStartLevel(currentSL);
        Object[] expectedFrameworkEvents = new Object[1];
        expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
        Object[] actualFrameworkEvents = frameworkListenerResults.getResults(1);
        compareResults(expectedFrameworkEvents, actualFrameworkEvents);
    }
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) BundleEvent(org.osgi.framework.BundleEvent) Endpoint(javax.xml.ws.Endpoint)

Example 28 with BundleEvent

use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testLegacyLazyStart.

public void testLegacyLazyStart() throws Exception {
    // $NON-NLS-1$
    Bundle legacy = installer.installBundle("legacy.lazystart");
    // $NON-NLS-1$
    Bundle legacyA = installer.installBundle("legacy.lazystart.a");
    // $NON-NLS-1$
    Bundle legacyB = installer.installBundle("legacy.lazystart.b");
    // $NON-NLS-1$
    Bundle legacyC = installer.installBundle("legacy.lazystart.c");
    // $NON-NLS-1$
    assertTrue("legacy lazy start resolve", installer.resolveBundles(new Bundle[] { legacy, legacyA, legacyB, legacyC }));
    // $NON-NLS-1$
    ((ITestRunner) legacy.loadClass("legacy.lazystart.SimpleLegacy").newInstance()).testIt();
    Object[] expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, legacyA);
    Object[] actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
    // $NON-NLS-1$
    ((ITestRunner) legacy.loadClass("legacy.lazystart.TrueExceptionLegacy1").newInstance()).testIt();
    // $NON-NLS-1$
    assertTrue("exceptions no event", simpleResults.getResults(0).length == 0);
    // $NON-NLS-1$
    ((ITestRunner) legacy.loadClass("legacy.lazystart.TrueExceptionLegacy2").newInstance()).testIt();
    expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, legacyB);
    actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
    // $NON-NLS-1$
    ((ITestRunner) legacy.loadClass("legacy.lazystart.FalseExceptionLegacy1").newInstance()).testIt();
    // $NON-NLS-1$
    assertTrue("exceptions no event", simpleResults.getResults(0).length == 0);
    // $NON-NLS-1$
    ((ITestRunner) legacy.loadClass("legacy.lazystart.FalseExceptionLegacy2").newInstance()).testIt();
    expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, legacyC);
    actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent)

Example 29 with BundleEvent

use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testSystemBundleListener.

public void testSystemBundleListener() throws BundleException, InterruptedException {
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    config.mkdirs();
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    Equinox equinox = new Equinox(configuration);
    equinox.start();
    BundleContext systemContext = equinox.getBundleContext();
    final AtomicInteger stoppingEvent = new AtomicInteger();
    final AtomicInteger stoppedEvent = new AtomicInteger();
    BundleListener systemBundleListener = new SynchronousBundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            if (event.getBundle().getBundleId() == 0) {
                switch(event.getType()) {
                    case BundleEvent.STOPPING:
                        stoppingEvent.incrementAndGet();
                        break;
                    case BundleEvent.STOPPED:
                        stoppedEvent.incrementAndGet();
                    default:
                        break;
                }
            }
        }
    };
    systemContext.addBundleListener(systemBundleListener);
    equinox.stop();
    equinox.waitForStop(5000);
    assertEquals("Wrong number of STOPPING events", 1, stoppingEvent.get());
    assertEquals("Wrong number of STOPPED events", 1, stoppedEvent.get());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BundleEvent(org.osgi.framework.BundleEvent) BundleListener(org.osgi.framework.BundleListener) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) File(java.io.File) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener) BundleContext(org.osgi.framework.BundleContext)

Example 30 with BundleEvent

use of org.osgi.framework.BundleEvent in project opennms by OpenNMS.

the class NCSCriteriaServiceManager method setBundleContext.

public void setBundleContext(BundleContext context) {
    m_bundleContext = context;
    m_bundleContext.addBundleListener(new BundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            switch(event.getType()) {
                case BundleEvent.STOPPING:
                    removeAllServices();
            }
        }
    });
}
Also used : BundleEvent(org.osgi.framework.BundleEvent) BundleListener(org.osgi.framework.BundleListener)

Aggregations

BundleEvent (org.osgi.framework.BundleEvent)53 Bundle (org.osgi.framework.Bundle)41 Test (org.junit.Test)12 SynchronousBundleListener (org.osgi.framework.SynchronousBundleListener)12 BundleListener (org.osgi.framework.BundleListener)9 FrameworkEvent (org.osgi.framework.FrameworkEvent)7 StartLevel (org.osgi.service.startlevel.StartLevel)7 BundleException (org.osgi.framework.BundleException)6 File (java.io.File)5 BundleContext (org.osgi.framework.BundleContext)5 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Endpoint (javax.xml.ws.Endpoint)3 BundleTracker (org.osgi.util.tracker.BundleTracker)3 BundleTrackerCustomizer (org.osgi.util.tracker.BundleTrackerCustomizer)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2