Java Code Examples for org.osgi.framework.BundleEvent#STOPPING

The following examples show how to use org.osgi.framework.BundleEvent#STOPPING . 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 File: SCR.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Process bundle components when it starts.
 */
public void bundleChanged(BundleEvent event) {
  postponeCheckin();
  try {
    final Bundle bundle = event.getBundle();

    switch (event.getType()) {
    case BundleEvent.LAZY_ACTIVATION:
      lazy.add(bundle);
      processBundle(bundle);
      break;
    case BundleEvent.STARTED:
      if (!lazy.remove(bundle)) {
        processBundle(bundle);
      }
      break;
    case BundleEvent.STOPPING:
      lazy.remove(bundle);
      removeBundle(bundle, ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED);
      break;
    }
  } finally {
    postponeCheckout();
  }
}
 
Example 2
Source File: PluginImageHelper.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void bundleChanged(BundleEvent event) {
	if (event.getType() == BundleEvent.STOPPING
			&& event.getBundle().getBundleId() == getPlugin().getBundle().getBundleId()) {
		dispose();
	}
}
 
Example 3
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String bundleEventName(int type)
{
  switch (type) {
  case BundleEvent.INSTALLED:
    return "installed";
  case BundleEvent.STARTED:
    return "started";
  case BundleEvent.STOPPED:
    return "stopped";
  case BundleEvent.UNINSTALLED:
    return "uninstalled";
  case BundleEvent.UPDATED:
    return "updated";
  case BundleEvent.RESOLVED:
    return "resolved";
  case BundleEvent.UNRESOLVED:
    return "unresolved";
  case BundleEvent.STARTING:
    return "starting";
  case BundleEvent.STOPPING:
    return "stopping";
  case BundleEvent.LAZY_ACTIVATION:
    return "lazyActivation";
  default:
    return "<" + type + ">";
  }
}
 
Example 4
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * notify all bundle listeners.
 * 
 * @param state
 *            the new state.
 * @param bundle
 *            the bundle.
 */
void notifyBundleListeners(final int state, final Bundle bundle,
		final Bundle origin) {
	if (syncBundleListeners.isEmpty() && bundleListeners.isEmpty()) {
		return;
	}

	final BundleEvent event = new BundleEvent(state, bundle, origin);

	final SynchronousBundleListener[] syncs;
	final BundleListener[] asyncs;

	// call the hooks, if any
	if (!bundleEventHooks.isEmpty()) {
		final ArrayList<SynchronousBundleListener> syncListeners = new ArrayList<SynchronousBundleListener>(
				syncBundleListeners);
		final ArrayList<BundleListener> asyncListeners = new ArrayList<BundleListener>(
				bundleListeners);

		final ConciergeCollections.DeltaTrackingRemoveOnlyList<BundleContext> contexts = new ConciergeCollections.DeltaTrackingRemoveOnlyList<BundleContext>(
				bundleListenerMap.keySet());

		for (final ServiceReferenceImpl<org.osgi.framework.hooks.bundle.EventHook> sref : bundleEventHooks) {
			final org.osgi.framework.hooks.bundle.EventHook eventHook = sref
					.getService(Concierge.this);
			if (eventHook != null) {
				try {
					eventHook.event(event, contexts);
				} catch (final Throwable t) {
					// TODO: to log?
				}
			}
			sref.ungetService(Concierge.this);
		}

		for (final BundleContext removed : contexts.getRemoved()) {
			if(removed != this.context){ // system bundle contexts listeners always gets events
				for (final BundleListener listener : bundleListenerMap
					.get(removed)) {
					syncListeners.remove(listener);
					asyncListeners.remove(listener);
				}
			}
		}

		syncs = syncListeners.toArray(
				new SynchronousBundleListener[syncListeners.size()]);
		asyncs = asyncListeners
				.toArray(new BundleListener[asyncListeners.size()]);
	} else {
		syncs = syncBundleListeners.toArray(
				new SynchronousBundleListener[syncBundleListeners.size()]);
		asyncs = bundleListeners
				.toArray(new BundleListener[bundleListeners.size()]);
	}

	for (int i = 0; i < syncs.length; i++) {
		syncs[i].bundleChanged(event);
	}

	// asynchronous listeners do not get these events
	final int type = event.getType();
	if (bundleListeners.isEmpty() || (type & (BundleEvent.STARTING
			| BundleEvent.STOPPING | BundleEvent.LAZY_ACTIVATION)) > 0) {
		return;
	}

	for (int i = 0; i < asyncs.length; i++) {
		asyncs[i].bundleChanged(event);
	}
}