下面列出了org.osgi.framework.BundleEvent#UNINSTALLED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
}
@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:
}
}
public Icon getBundleEventIcon(int type)
{
switch (type) {
case BundleEvent.INSTALLED:
return installIcon;
case BundleEvent.STARTED:
return startIcon;
case BundleEvent.STOPPED:
return stopIcon;
case BundleEvent.UNINSTALLED:
return uninstallIcon;
case BundleEvent.UPDATED:
return updateIcon;
default:
return null;
}
}
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();
}
public synchronized void stopBundle() throws BundleException {
if (this.state == BundleEvent.INSTALLED) {
throw new IllegalStateException("Cannot stop uninstalled bundle "
+ toString());
} else if (this.state == BundleEvent.RESOLVED) {
this.state = BundleEvent.UNINSTALLED;
try {
if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
log.info("Framework: Bundle " + toString() + " stopped.");
}
Framework.clearBundleTrace(this);
this.state = BundleEvent.STOPPED;
Framework.notifyBundleListeners(BundleEvent.STOPPED, this);
isValid = false;
} catch (Throwable th) {
Framework.clearBundleTrace(this);
this.state = BundleEvent.STOPPED;
Framework.notifyBundleListeners(BundleEvent.STOPPED, this);
isValid = false;
}
}
}
static void shutdown(boolean restart) {
System.out.println("---------------------------------------------------------");
System.out.println(" OpenAtlas OSGi shutting down ...");
System.out.println(" Bye !");
System.out.println("---------------------------------------------------------");
systemBundle.state = BundleEvent.UNINSTALLED;
systemBundle.setLevel(getBundles().toArray(new Bundle[bundles.size()]), 0, true);
bundles.clear();
systemBundle.state = BundleEvent.INSTALLED;
if (restart) {
try {
startup();
} catch (Throwable th) {
th.printStackTrace();
}
}
}
/**
* 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);
}
}
}
/**
* 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);
}
public void bundleChanged(BundleEvent event)
{
if (BundleEvent.UNINSTALLED==event.getType()) {
synchronized(prefsMap) {
PreferencesServiceImpl prefs
= (PreferencesServiceImpl)prefsMap.get(event.getBundle());
if(prefs != null) {
prefs.cleanup();
}
}
}
}
/**
* 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));
}
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 + ">";
}
}
@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);
}
}
/** {@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());
}
}
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);
}
public void bundleChanged(BundleEvent e)
{
if (e.getType() == BundleEvent.UNINSTALLED) {
tempDrivers.remove(e.getBundle());
}
}
/**
* 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");
}
// }
}
@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:
}
}