org.osgi.framework.BundleEvent#getType ( )源码实例Demo

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

@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
/**
 * Depending on the action committed against the bundle supplier of automation resources, this method performs the
 * appropriate action - calls for it's host bundles:
 * <ul>
 * {@link AbstractResourceBundleProvider#processAutomationProviderUninstalled(Bundle)} method
 * </ul>
 * or
 * <ul>
 * {@link AbstractResourceBundleProvider#processAutomationProvider(Bundle)} method
 * </ul>
 *
 * @param event for a bundle tracked by the {@code BundleTracker}. It has been for adding, modifying or removing the
 *            bundle.
 */
protected void processBundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if (HostFragmentMappingUtil.isFragmentBundle(bundle)) {
        for (Bundle host : HostFragmentMappingUtil.returnHostBundles(bundle)) {
            provider.processAutomationProvider(host);
        }
    } else {
        switch (event.getType()) {
            case BundleEvent.UNINSTALLED:
                provider.processAutomationProviderUninstalled(bundle);
                break;
            default:
                provider.processAutomationProvider(bundle);
        }
    }
}
 
源代码4 项目: knopflerfish.org   文件: LogConfigImpl.java
@Override
public void bundleChanged(BundleEvent event) {
  switch (event.getType()) {
    case BundleEvent.INSTALLED: // Fall through
    case BundleEvent.UPDATED:
      computeBidFilter(bidFilters, event.getBundle());
      break;
    case BundleEvent.UNINSTALLED:
      final Long key = new Long(event.getBundle().getBundleId());
      synchronized (bidFilters) {
        bidFilters.remove(key);
      }
      break;
    default:
  }
}
 
源代码5 项目: knopflerfish.org   文件: Spin.java
public void bundleChanged(BundleEvent ev) {
  Long    id = new Long(ev.getBundle().getBundleId());
  synchronized(bundles) {
    BX bx = bundles.get(id);

    switch(ev.getType()) {
    case BundleEvent.INSTALLED:
      if(bx == null) {
        bx = new BX(this, ev.getBundle());
        bundles.put(id, bx);
        bxNeedRecalc = true;
      }
      break;
    case BundleEvent.UNINSTALLED:
      if(bx != null) {
        bundles.remove(id);
        bxNeedRecalc = true;
      }
      break;
    }
  }
  repaint();
}
 
源代码6 项目: knopflerfish.org   文件: SCR.java
/**
 * 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();
  }
}
 
源代码7 项目: AtlasForAndroid   文件: BundleLifecycleHandler.java
@SuppressLint({"NewApi"})
public void bundleChanged(BundleEvent bundleEvent) {
    switch (bundleEvent.getType()) {
        case DeviceSecuritySDK.ENVIRONMENT_ONLINE /*0*/:
            loaded(bundleEvent.getBundle());
        case OpenBase.OAUTH_CREATE /*1*/:
            installed(bundleEvent.getBundle());
        case StaticDataStore.SECURITY_KEY_TYPE /*2*/:
            if (isLewaOS()) {
                if (Looper.myLooper() == null) {
                    Looper.prepare();
                }
                started(bundleEvent.getBundle());
            } else if (Framework.isFrameworkStartupShutdown()) {
                BundleStartTask bundleStartTask = new BundleStartTask();
                if (VERSION.SDK_INT > 11) {
                    bundleStartTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Bundle[]{bundleEvent.getBundle()});
                    return;
                }
                bundleStartTask.execute(new Bundle[]{bundleEvent.getBundle()});
            } else {
                started(bundleEvent.getBundle());
            }
        case StaticDataStore.INVALID_KEY_TYPE /*4*/:
            stopped(bundleEvent.getBundle());
        case IStaticDataEncryptComponent.GCRY_CIPHER_SERPENT128 /*8*/:
            updated(bundleEvent.getBundle());
        case IStaticDataEncryptComponent.GCRY_CIPHER_AES128 /*16*/:
            uninstalled(bundleEvent.getBundle());
        default:
    }
}
 
源代码8 项目: ACDD   文件: SecurityBundleListner.java
public void bundleChanged(BundleEvent bundleEvent) {

        switch (bundleEvent.getType()) {
            case BundleEvent.INSTALLED:
            case BundleEvent.UPDATED:
                Message obtain = Message.obtain();
                obtain.obj = bundleEvent.getBundle().getLocation();
                this.mSecurityCheckHandler.sendMessage(obtain);
                return;
            default:
                return;
        }
    }
 
源代码9 项目: cxf   文件: CXFExtensionBundleListener.java
/** {@inheritDoc}*/
public void bundleChanged(BundleEvent event) {
    if (event.getType() == BundleEvent.RESOLVED && id != event.getBundle().getBundleId()) {
        register(event.getBundle());
    } else if (event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED) {
        unregister(event.getBundle().getBundleId());
    }
}
 
源代码10 项目: M2Doc   文件: EclipseClassProvider.java
/**
 * Constructor.
 * 
 * @param context
 *            the {@link BundleContext}
 * @param classLoader
 *            the fall back {@link ClassLoader}
 */
public EclipseClassProvider(BundleContext context, ClassLoader classLoader) {
    super(classLoader);
    this.context = context;
    for (Bundle bundle : context.getBundles()) {
        bundles.put(bundle.getSymbolicName(), bundle);
    }
    listener = new BundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            switch (event.getType()) {
                case BundleEvent.INSTALLED:
                    bundles.put(event.getBundle().getSymbolicName(), event.getBundle());
                    break;

                case BundleEvent.UNINSTALLED:
                    bundles.remove(event.getBundle().getSymbolicName());
                    break;

                default:
                    // nothing to do here
                    break;
            }
        }
    };
    context.addBundleListener(listener);
}
 
源代码11 项目: xtext-eclipse   文件: PluginImageHelper.java
@Override
public void bundleChanged(BundleEvent event) {
	if (event.getType() == BundleEvent.STOPPING
			&& event.getBundle().getBundleId() == getPlugin().getBundle().getBundleId()) {
		dispose();
	}
}
 
源代码12 项目: flowable-engine   文件: Extender.java
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if (event.getType() == BundleEvent.RESOLVED) {
        checkBundle(bundle);
    } else if (event.getType() == BundleEvent.STARTED) {
        checkBundleScriptEngines(bundle);
    }
}
 
源代码13 项目: sis   文件: OSGiActivator.java
/**
 * Invoked when an other module has been installed or un-installed.
 * This method notifies the Apache SIS library that the classpath may have changed.
 *
 * @param  event  the event that describe the life-cycle change.
 */
@Override
public void bundleChanged(final BundleEvent event) {
    switch (event.getType()) {
        case BundleEvent.STARTED: {
            SystemListener.fireClasspathChanged();
            break;
        }
        case BundleEvent.STOPPED: {
            SystemListener.fireClasspathChanged();
            SystemListener.removeModule(event.getBundle().getSymbolicName());
            break;
        }
    }
}
 
public void bundleChanged(BundleEvent event)
{
  if (BundleEvent.UNINSTALLED==event.getType()) {
    synchronized(prefsMap) {
      PreferencesServiceImpl prefs
        = (PreferencesServiceImpl)prefsMap.get(event.getBundle());
      if(prefs != null) {
        prefs.cleanup();
      }
    }
  }
}
 
源代码15 项目: siddhi   文件: SiddhiExtensionLoader.java
@Override
public void bundleChanged(BundleEvent bundleEvent) {
    if (bundleEvent.getType() == BundleEvent.STARTED) {
        addExtensions(bundleEvent.getBundle());
    } else {
        removeExtensions(bundleEvent.getBundle());
    }
}
 
源代码16 项目: knopflerfish.org   文件: LogFrameworkListener.java
/**
  * The bundle event callback method inserts all bundle events into the
  * log. Events are all assigned the log level info.
  * 
  * @param be
  *            the bundle event that has occured.
  */
 public void bundleChanged(BundleEvent be) {
     String msg = null;
     switch (be.getType()) {
     case BundleEvent.INSTALLED:
         msg = "BundleEvent INSTALLED";
         break;
     case BundleEvent.STARTED:
         msg = "BundleEvent STARTED";
         break;
     case BundleEvent.STOPPED:
         msg = "BundleEvent STOPPED";
         break;
     case BundleEvent.UNINSTALLED:
         msg = "BundleEvent UNINSTALLED";
         break;
     case BundleEvent.UPDATED:
         msg = "BundleEvent UPDATED";
         break;
     case BundleEvent.RESOLVED:
         msg = "BundleEvent RESOLVED";
         break;  
     case BundleEvent.UNRESOLVED:
         msg = "BundleEvent UNRESOLVED";
         break;
/*     case BundleEvent.STARTING:
         msg = "BundleEvent STARTING";
         break;
     case BundleEvent.STOPPING:
         msg = "BundleEvent STOPPING";
         break;  
         */   
     }
     lrsf.log(new LogEntryImpl(be.getBundle(), LogService.LOG_INFO, msg));
 }
 
@Override
public void bundleChanged(BundleEvent event)
{
  if (event.getType() == BundleEvent.UNINSTALLED) {
    final String uninstalledBundleLocation = event.getBundle().getLocation();
    existingBundleLocations.remove(uninstalledBundleLocation);
    findAndUnbindConfigurationsDynamicallyBoundTo(uninstalledBundleLocation);
  } else if (event.getType() == BundleEvent.INSTALLED) {
    final String installedBundleLocation = event.getBundle().getLocation();
    existingBundleLocations.put(installedBundleLocation,
                                installedBundleLocation);
  }
}
 
源代码18 项目: 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);
	}
}
 
源代码19 项目: knopflerfish.org   文件: MultiListener.java
/**
 * A listener for events sent by bundles
 * @param bundleEvent The event sent by the bundle
 * @author Johnny Baveras
 */


public void bundleChanged(BundleEvent bundleEvent) {
  String topic = null;
  boolean knownMessageType = true;

  switch (bundleEvent.getType()) {
  case BundleEvent.INSTALLED:
    topic = INSTALLED_TOPIC;
    break;
  case BundleEvent.STARTED:
    topic = STARTED_TOPIC;
    break;
  case BundleEvent.STOPPED:
    topic = STOPPED_TOPIC;
    break;
  case BundleEvent.UPDATED:
    topic = UPDATED_TOPIC;
    break;
  case BundleEvent.UNINSTALLED:
    topic = UNINSTALLED_TOPIC;
    break;
  case BundleEvent.RESOLVED:
    topic = RESOLVED_TOPIC;
    break;
  case BundleEvent.UNRESOLVED:
    topic = UNRESOLVED_TOPIC;
    break;
  default:
    /* Setting the boolean to false if an unknown event arrives */
    knownMessageType = false;
    break;
  }


  /* Stores the properties of the event in the dictionary, if the event is known */
  if (knownMessageType) {
    if(!Activator.handlerTracker.anyHandlersMatching(topic)) {
      return;
    }
    Map<String,Object> props = new HashMap<String,Object>();
    Bundle bundle = bundleEvent.getBundle();
    putProp(props, EventConstants.EVENT, bundleEvent);
    putProp(props, "bundle.id", new Long(bundle.getBundleId()));
    putProp(props, EventConstants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
    putProp(props, "bundle", bundle);
    /* Tries posting the event once the properties are set */
    try {
      Activator.eventAdmin.postEvent(new Event(topic, props));
    } catch (Exception e) {
      Activator.log.error("EXCEPTION in bundleChanged()", e);
    }
  } else {
    /* Logs an error if the event, which arrived, were of an unknown type */
    Activator.log.error("Recieved unknown bundle event message (type="
              +bundleEvent.getType() +"), discarding");
  }
  // }
}
 
源代码20 项目: ACDD   文件: BundleLifecycleHandler.java
@Override
@SuppressLint({"NewApi"})
public void bundleChanged(BundleEvent bundleEvent) {
    switch (bundleEvent.getType()) {
        case BundleEvent.LOADED:
            loaded(bundleEvent.getBundle());
            break;
        case BundleEvent.INSTALLED:
            installed(bundleEvent.getBundle());
            break;
        case BundleEvent.STARTED:
            if (isLewaOS()) {
                if (Looper.myLooper() == null) {
                    Looper.prepare();
                }
                started(bundleEvent.getBundle());
            } else if (Framework.isFrameworkStartupShutdown()) {
                BundleStartTask bundleStartTask = new BundleStartTask();
                if (VERSION.SDK_INT > 11) {
                    bundleStartTask.executeOnExecutor(
                            AsyncTask.THREAD_POOL_EXECUTOR,
                            bundleEvent.getBundle());
                    return;
                }
                bundleStartTask
                        .execute(bundleEvent.getBundle());
            } else {
                started(bundleEvent.getBundle());
            }
            break;
        case BundleEvent.STOPPED:
            stopped(bundleEvent.getBundle());
            break;
        case BundleEvent.UPDATED:
            updated(bundleEvent.getBundle());
            break;
        case BundleEvent.UNINSTALLED:

        {
            uninstalled(bundleEvent.getBundle());
            break;
        }
        default:
    }
}