use of org.osgi.framework.BundleActivator in project bnd by bndtools.
the class Launcher method activate.
public int activate() throws Exception {
Policy.setPolicy(new AllPolicy());
systemBundle = createFramework();
if (systemBundle == null)
return LauncherConstants.ERROR;
active.set(true);
doTimeoutHandler();
doSecurity();
// Initialize this framework so it becomes STARTING
systemBundle.start();
trace("system bundle started ok");
BundleContext systemContext = systemBundle.getBundleContext();
ServiceReference ref = systemContext.getServiceReference(PackageAdmin.class.getName());
if (ref != null) {
padmin = (PackageAdmin) systemContext.getService(ref);
} else
trace("could not get package admin");
systemContext.addServiceListener(this, "(&(|(objectclass=" + Runnable.class.getName() + ")(objectclass=" + Callable.class.getName() + "))(main.thread=true))");
int result = LauncherConstants.OK;
// Start embedded activators
trace("start embedded activators");
if (parms.activators != null) {
ClassLoader loader = getClass().getClassLoader();
for (Object token : parms.activators) {
try {
Class<?> clazz = loader.loadClass((String) token);
BundleActivator activator = (BundleActivator) clazz.getConstructor().newInstance();
if (isImmediate(activator)) {
start(systemContext, result, activator);
}
embedded.add(activator);
trace("adding activator %s", activator);
} catch (Exception e) {
throw new IllegalArgumentException("Embedded Bundle Activator incorrect: " + token, e);
}
}
}
update(System.currentTimeMillis() + 100);
if (parms.trace) {
report(out);
}
for (BundleActivator activator : embedded) if (!isImmediate(activator))
result = start(systemContext, result, activator);
return result;
}
Aggregations