org.osgi.framework.BundleEvent#STARTING源码实例Demo

下面列出了org.osgi.framework.BundleEvent#STARTING 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    
    // this bundle is already starting by the time this is invoked. We also can't get proper timing
    // from the framework bundle
    
    if ( bundle.getBundleId() == Constants.SYSTEM_BUNDLE_ID 
            || bundle.getBundleId() == ourBundleId ) {
        return;
    }
    
    synchronized (bundleToStartTime) {

        switch (event.getType()) {
            case BundleEvent.STARTING:
                bundleToStartTime.put(bundle.getBundleId(), new StartTime(bundle.getSymbolicName(), clock.millis()));
                break;

            case BundleEvent.STARTED:
                StartTime startTime = bundleToStartTime.get(bundle.getBundleId());
                if ( startTime == null ) {
                    Log.debug(getClass(), "No previous data for started bundle {}/{}", new Object[] { bundle.getBundleId(), bundle.getSymbolicName() });
                    return;
                }
                startTime.started(clock.millis());
                break;
            
            default: // nothing to do here
                break;
        }
    }
}
 
源代码2 项目: knopflerfish.org   文件: Util.java
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 + ">";
  }
}
 
源代码3 项目: netbeans   文件: Netigso.java
final void notifyBundleChange(final String symbolicName, final Version version, final int action) {
    final Exception stack = Netigso.LOG.isLoggable(Level.FINER) ? new Exception("StackTrace") : null;
    final Runnable doLog = new Runnable() {
        @Override
        public void run() {
            if (isEnabled(symbolicName)) {
                return;
            }
            final Mutex mutex = Main.getModuleSystem().getManager().mutex();
            if (!mutex.isReadAccess()) {
                mutex.postReadRequest(this);
                return;
            }
            String type = "" + action;
            Level notify = Level.INFO;
            switch (action) {
                case BundleEvent.INSTALLED:
                    return; // no message for installed
                case BundleEvent.RESOLVED:
                    type = "resolved";
                    break;
                case BundleEvent.STARTED:
                    type = "started";
                    break;
                case BundleEvent.STOPPED:
                    type = "stopped";
                    break;
                case BundleEvent.UNINSTALLED:
                    return; // nothing for uninstalled
                case BundleEvent.LAZY_ACTIVATION:
                    type = "lazy";
                    notify = Level.FINEST;
                    break;
                case BundleEvent.STARTING:
                    type = "starting";
                    notify = Level.FINEST;
                    break;
            }
            Netigso.LOG.log(notify, "bundle {0}@{2} {1}", new Object[]{
                        symbolicName, type, version
                    });
            if (stack != null) {
                Netigso.LOG.log(Level.FINER, null, stack);
            }
        }
    };
    RP.post(doLog);
}
 
源代码4 项目: concierge   文件: Concierge.java
/**
 * 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);
	}
}