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);
}
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations