Search in sources :

Example 16 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project aries by apache.

the class BundleFrameworkImpl method setupStartLevelToPreventAutostart.

/**
   * Name says it all if we don't make some adjustments bundles will be autostarted, which in the
   * grand scheme of things causes extenders to act on the inner bundles before the outer composite is even
   * resolved ...
   */
private void setupStartLevelToPreventAutostart(BundleContext frameworkBundleContext) {
    ServiceReference ref = frameworkBundleContext.getServiceReference(StartLevel.class.getName());
    if (ref != null) {
        StartLevel sl = (StartLevel) frameworkBundleContext.getService(ref);
        if (sl != null) {
            // make sure new bundles are *not* automatically started (because that causes havoc)
            sl.setInitialBundleStartLevel(sl.getStartLevel() + 1);
            frameworkBundleContext.ungetService(ref);
        }
    }
}
Also used : StartLevel(org.osgi.service.startlevel.StartLevel) ServiceReference(org.osgi.framework.ServiceReference)

Example 17 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project aries by apache.

the class FrameworkMBeanHandler method open.

/**
     * @see org.apache.aries.jmx.MBeanHandler#open()
     */
public void open() {
    ServiceReference adminRef = context.getServiceReference(PackageAdmin.class.getCanonicalName());
    PackageAdmin packageAdmin = (PackageAdmin) context.getService(adminRef);
    ServiceReference startLevelRef = context.getServiceReference(StartLevel.class.getCanonicalName());
    StartLevel startLevel = (StartLevel) context.getService(startLevelRef);
    FrameworkMBean framework = new Framework(context, startLevel, packageAdmin);
    try {
        mbean = new StandardMBean(framework, FrameworkMBean.class);
    } catch (NotCompliantMBeanException e) {
        logger.log(LogService.LOG_ERROR, "Not compliant MBean", e);
    }
    agentContext.registerMBean(this);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) StartLevel(org.osgi.service.startlevel.StartLevel) FrameworkMBean(org.osgi.jmx.framework.FrameworkMBean) ServiceReference(org.osgi.framework.ServiceReference)

Example 18 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project aries by apache.

the class BundleStateMBeanHandler method open.

/**
     * @see org.apache.aries.jmx.MBeanHandler#open()
     */
public void open() {
    packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
    startLevelRef = bundleContext.getServiceReference(StartLevel.class.getName());
    StartLevel startLevel = (StartLevel) bundleContext.getService(startLevelRef);
    bundleStateMBean = new BundleState(bundleContext, packageAdmin, startLevel, stateConfig, logger);
    try {
        mbean = new RegistrableStandardEmitterMBean(bundleStateMBean, BundleStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        logger.log(LogService.LOG_ERROR, "Failed to instantiate MBean for " + BundleStateMBean.class.getName(), e);
    }
    agentContext.registerMBean(this);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RegistrableStandardEmitterMBean(org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean) StartLevel(org.osgi.service.startlevel.StartLevel) BundleStateMBean(org.osgi.jmx.framework.BundleStateMBean)

Example 19 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testSystemBundle14.

public void testSystemBundle14() {
    // Test startlevel property
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle14");
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    // $NON-NLS-1$
    configuration.put(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "10");
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    StartLevel st = (StartLevel) equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(StartLevel.class.getName()));
    // $NON-NLS-1$
    assertNotNull("StartLevel service is null", st);
    // $NON-NLS-1$
    assertEquals("Unexpected start level", 10, st.getStartLevel());
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    FrameworkEvent stopEvent = null;
    try {
        stopEvent = equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertNotNull("Stop event is null", stopEvent);
    // $NON-NLS-1$
    assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FrameworkEvent(org.osgi.framework.FrameworkEvent) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel) StartLevel(org.osgi.service.startlevel.StartLevel) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Example 20 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testStartTransientByLoadClass.

public void testStartTransientByLoadClass() throws Exception {
    // install a bundle and set its start-level high, then crank up the framework start-level.  This should result in no events
    // $NON-NLS-1$
    Bundle osgiA = installer.installBundle("osgi.lazystart.a");
    installer.resolveBundles(new Bundle[] { osgiA });
    StartLevel startLevel = installer.getStartLevel();
    startLevel.setBundleStartLevel(osgiA, startLevel.getStartLevel() + 10);
    // test transient start by loadClass
    startLevel.setStartLevel(startLevel.getStartLevel() + 15);
    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);
    startLevel.setStartLevel(startLevel.getStartLevel() - 15);
    expectedFrameworkEvents = new Object[1];
    expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
    actualFrameworkEvents = frameworkListenerResults.getResults(1);
    compareResults(expectedFrameworkEvents, actualFrameworkEvents);
    Object[] expectedEvents = new Object[0];
    Object[] actualEvents = simpleResults.getResults(0);
    compareResults(expectedEvents, actualEvents);
    // now load a class from it before the start-level is met.  This should result in no events
    // $NON-NLS-1$
    osgiA.loadClass("osgi.lazystart.a.ATest");
    expectedEvents = new Object[0];
    actualEvents = simpleResults.getResults(0);
    compareResults(expectedEvents, actualEvents);
    startLevel.setStartLevel(startLevel.getStartLevel() + 15);
    expectedFrameworkEvents = new Object[1];
    expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
    actualFrameworkEvents = frameworkListenerResults.getResults(1);
    compareResults(expectedFrameworkEvents, actualFrameworkEvents);
    expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
    actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
    startLevel.setStartLevel(startLevel.getStartLevel() - 15);
    expectedFrameworkEvents = new Object[1];
    expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
    actualFrameworkEvents = frameworkListenerResults.getResults(1);
    compareResults(expectedFrameworkEvents, actualFrameworkEvents);
    expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STOPPED, osgiA);
    actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
    // now load a class while start-level is met.
    startLevel.setStartLevel(startLevel.getStartLevel() + 15);
    expectedFrameworkEvents = new Object[1];
    expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
    actualFrameworkEvents = frameworkListenerResults.getResults(1);
    compareResults(expectedFrameworkEvents, actualFrameworkEvents);
    // $NON-NLS-1$
    osgiA.loadClass("osgi.lazystart.a.ATest");
    expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
    actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
    startLevel.setStartLevel(startLevel.getStartLevel() - 15);
    expectedFrameworkEvents = new Object[1];
    expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
    actualFrameworkEvents = frameworkListenerResults.getResults(1);
    compareResults(expectedFrameworkEvents, actualFrameworkEvents);
    expectedEvents = new Object[1];
    expectedEvents[0] = new BundleEvent(BundleEvent.STOPPED, osgiA);
    actualEvents = simpleResults.getResults(1);
    compareResults(expectedEvents, actualEvents);
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) BundleEvent(org.osgi.framework.BundleEvent)

Aggregations

StartLevel (org.osgi.service.startlevel.StartLevel)22 Bundle (org.osgi.framework.Bundle)12 FrameworkEvent (org.osgi.framework.FrameworkEvent)10 BundleEvent (org.osgi.framework.BundleEvent)7 ServiceReference (org.osgi.framework.ServiceReference)7 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)6 Endpoint (javax.xml.ws.Endpoint)4 BundleContext (org.osgi.framework.BundleContext)4 Logger (org.apache.aries.jmx.Logger)3 Test (org.junit.Test)3 BundleException (org.osgi.framework.BundleException)3 File (java.io.File)2 HashMap (java.util.HashMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 MBeanServer (javax.management.MBeanServer)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ObjectName (javax.management.ObjectName)2 Equinox (org.eclipse.osgi.launch.Equinox)2 BundleListener (org.osgi.framework.BundleListener)2 Field (java.lang.reflect.Field)1