Java Code Examples for org.osgi.framework.Bundle#START_ACTIVATION_POLICY

The following examples show how to use org.osgi.framework.Bundle#START_ACTIVATION_POLICY . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: concierge   File: BundleImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * the actual starting happens here. This method does not modify the
 * persistent metadata.
 * 
 * @throws BundleException
 *             if the bundle cannot be resolved or the Activator throws an
 *             exception.
 */
synchronized void activate(final int options) throws BundleException {
	if (state == ACTIVE) {
		return;
	}
	if (currentRevision.isFragment()) {
		return;
	}

	// step4
	if (state == INSTALLED) {
		// this time, it is critical to get the bundle resolved
		// so if we need exports from other unresolved bundles,
		// we will try to resolve them (recursively) to get the bundle
		// started
		currentRevision.resolve(true);
	}

	// step5
	this.context = framework.createBundleContext(this);
	if ((options & Bundle.START_ACTIVATION_POLICY) > 0 && lazyActivation) {
		if (state != STARTING) {
			beingLazy = true;
			state = STARTING;
			framework.notifyBundleListeners(BundleEvent.LAZY_ACTIVATION,
					this);
		}
		synchronized (this) {
			notify();
		}
		return;
	} else {
		beingLazy = false;
	}

	activate0();
}
 
Example 2
public int cmdStart(Dictionary<String,?> opts, Reader in, PrintWriter out,
                    Session session) {
  int startOptions = 0;
  if (opts.get("-t") != null) {
    startOptions |= Bundle.START_TRANSIENT;
  }
  if (opts.get("-e") == null) {
    startOptions |= Bundle.START_ACTIVATION_POLICY;
  }

  final Bundle[] b = getBundles((String[]) opts.get("bundle"), true);
  boolean found = false;
  for (final Bundle element : b) {
    if (element != null) {
      try {
        element.start(startOptions);
        out.println("Started: " + showBundle(element));
      } catch (final BundleException e) {
        Throwable t = e;
        while (t instanceof BundleException
               && ((BundleException) t).getNestedException() != null) {
          t = ((BundleException) t).getNestedException();
        }
        out.println("Couldn't start bundle: " + showBundle(element)
                    + " (due to: " + t + ")");
        t.printStackTrace(out);
      }
      found = true;
    }
  }
  if (!found) {
    out.println("ERROR! No matching bundle");
    return 1;
  }
  return 0;
}
 
Example 3
int getStartOptions()
{
  int options = 0;
  if (itemStartOptionsTransient.getState()) {
    options |= Bundle.START_TRANSIENT;
  }
  if (itemStartOptionsPolicy.getState()) {
    options |= Bundle.START_ACTIVATION_POLICY;
  }
  return options;
}
 
Example 4
void syncStartLevel(BundleImpl bs) {
  try {
    if (fwCtx.debug.startlevel) {
      fwCtx.debug.println("syncstartlevel: " + bs);
    }
    synchronized (lock) {
      synchronized (fwCtx.resolver) {
        if (bs.getStartLevel() <= currentLevel) {
          final BundleGeneration current = bs.current();
          if ((bs.getState() & (Bundle.INSTALLED|Bundle.RESOLVED|Bundle.STOPPING)) != 0
              && current.archive.getAutostartSetting()!=-1) {
            if (fwCtx.debug.startlevel) {
              fwCtx.debug.println("startlevel: start " + bs);
            }
            int startOptions = Bundle.START_TRANSIENT;
            if (isBundleActivationPolicyUsed(current.archive)) {
              startOptions |= Bundle.START_ACTIVATION_POLICY;
            }
            bs.start(startOptions);
          }
        } else {
          if ((bs.getState() & (Bundle.ACTIVE|Bundle.STARTING)) != 0) {
            if (fwCtx.debug.startlevel) {
              fwCtx.debug.println("startlevel: stop " + bs);
            }
            bs.stop(Bundle.STOP_TRANSIENT);
          }
        }
      }
    }
  } catch (final Throwable t) {
    fwCtx.frameworkError(bs, t);
  }
}
 
Example 5
boolean isBundleActivationPolicyUsed(BundleArchive archive) {
  return archive != null && archive.getAutostartSetting() == Bundle.START_ACTIVATION_POLICY;
}
 
Example 6
/**
 * Start this framework.
 *
 * @see org.osgi.framework.Framework#start
 */
@Override
public void start(int options) throws BundleException {
  List<String> bundlesToStart = null;
  synchronized (lock) {
    waitOnOperation(lock, "Framework.start", true);

    switch (state) {
    case INSTALLED:
    case RESOLVED:
      doInit();
      // Fall through
    case STARTING:
      operation = ACTIVATING;
      break;
    case ACTIVE:
      return;
    default:
      throw new IllegalStateException("INTERNAL ERROR, Illegal state, " + state);
    }
    if (fwCtx.startLevelController == null) {
      bundlesToStart = fwCtx.storage.getStartOnLaunchBundles();
    }
  }

  if (fwCtx.startLevelController != null) {
    // start level open is delayed to this point to
    // correctly work at restart
    fwCtx.startLevelController.open();
  } else {
    // Start bundles according to their autostart setting.
    final Iterator<String> i = bundlesToStart.iterator();
    while (i.hasNext()) {
      final BundleImpl b = (BundleImpl)fwCtx.bundles.getBundle(i.next());
      try {
        final int autostartSetting = b.current().archive.getAutostartSetting();
        // Launch must not change the autostart setting of a bundle
        int option = Bundle.START_TRANSIENT;
        if (Bundle.START_ACTIVATION_POLICY == autostartSetting) {
          // Transient start according to the bundles activation policy.
          option |= Bundle.START_ACTIVATION_POLICY;
        }
        b.start(option);
      } catch (final BundleException be) {
        fwCtx.frameworkError(b, be);
      }
    }
  }
  synchronized (lock) {
    state = ACTIVE;
    operation = IDLE;
    lock.notifyAll();
    fwCtx.listeners.frameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, this, null));
  }
}