Search in sources :

Example 6 with BundleActivator

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;
}
Also used : BundleActivator(org.osgi.framework.BundleActivator) Callable(java.util.concurrent.Callable) BundleException(org.osgi.framework.BundleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) BundleContext(org.osgi.framework.BundleContext)

Aggregations

BundleActivator (org.osgi.framework.BundleActivator)6 IOException (java.io.IOException)3 BundleException (org.osgi.framework.BundleException)3 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)2 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Manifest (java.util.jar.Manifest)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 PojoServiceRegistry (org.apache.felix.connect.launch.PojoServiceRegistry)1 JackrabbitRepository (org.apache.jackrabbit.api.JackrabbitRepository)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1