Java Code Examples for org.osgi.framework.BundleEvent#STOPPED
The following examples show how to use
org.osgi.framework.BundleEvent#STOPPED .
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: Activator.java From netbeans with Apache License 2.0 | 6 votes |
public @Override void bundleChanged(BundleEvent event) { Bundle bundle = event.getBundle(); switch (event.getType()) { case BundleEvent.STARTED: // System.err.println("started " + bundle.getSymbolicName()); Dictionary<?,?> headers = bundle.getHeaders(); load(queue.offer(bundle, provides(headers), requires(headers), needs(headers))); break; case BundleEvent.STOPPED: // System.err.println("stopped " + bundle.getSymbolicName()); if (framework.getState() == Bundle.STOPPING) { // System.err.println("fwork stopping during " + bundle.getSymbolicName()); // ActiveQueue.stop(); } else { unload(queue.retract(bundle)); } break; } }
Example 2
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
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; } }
Example 3
Source File: BundleImpl.java From ACDD with MIT License | 6 votes |
public synchronized void startBundle() throws BundleException { if (this.state == BundleEvent.INSTALLED) { throw new IllegalStateException("Cannot start uninstalled bundle " + toString()); } else if (this.state != BundleEvent.RESOLVED) { if (this.state == BundleEvent.STARTED) { resolveBundle(true); } this.state = BundleEvent.UPDATED; try { isValid = true; this.state = BundleEvent.RESOLVED; Framework.notifyBundleListeners(BundleEvent.STARTED, this); if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) { log.info("Framework: Bundle " + toString() + " started."); } } catch (Throwable th) { Framework.clearBundleTrace(this); this.state = BundleEvent.STOPPED; String msg = "Error starting bundle " + toString(); log.error(msg,th); } } }
Example 4
Source File: BundleImpl.java From ACDD with MIT License | 6 votes |
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; } } }
Example 5
Source File: LogFrameworkListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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)); }
Example 6
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 7
Source File: BundleImpl.java From ACDD with MIT License | 5 votes |
private synchronized void resolveBundle(boolean recursive) throws BundleException { if (this.state != BundleEvent.STOPPED) { if (this.classloader == null) { this.classloader = new BundleClassLoader(this); } if (recursive) { this.classloader.resolveBundle(true, new HashSet(0)); this.state = BundleEvent.STOPPED; } else if (this.classloader.resolveBundle(false, null)) { this.state = BundleEvent.STOPPED; } Framework.notifyBundleListeners(BundleEvent.LOADED, this); } }
Example 8
Source File: Framework.java From ACDD with MIT License | 5 votes |
@Override public void setBundleStartLevel(Bundle bundle, int level) { if (bundle == this) { throw new IllegalArgumentException("Cannot set the start level for the system bundle."); } BundleImpl bundleImpl = (BundleImpl) bundle; if (bundleImpl.state == BundleEvent.INSTALLED) { throw new IllegalArgumentException("Bundle " + bundle + " has been uninstalled"); } else if (level <= 0) { throw new IllegalArgumentException("Start level " + level + " is not Component valid level"); } else { bundleImpl.currentStartlevel = level; bundleImpl.updateMetadata(); if (level <= Framework.startlevel && bundle.getState() != BundleEvent.RESOLVED && bundleImpl.persistently) { try { bundleImpl.startBundle(); } catch (Throwable e) { e.printStackTrace(); Framework.notifyFrameworkListeners(BundleEvent.STARTED, bundle, e); } } else if (level <= Framework.startlevel) { } else { if (bundle.getState() != BundleEvent.STOPPED || bundle.getState() != BundleEvent.STARTED) { try { bundleImpl.stopBundle(); } catch (Throwable e2) { Framework.notifyFrameworkListeners(BundleEvent.STARTED, bundle, e2); } } } } }
Example 9
Source File: OSGIServiceLoader.java From incubator-tamaya with Apache License 2.0 | 5 votes |
@Override public void bundleChanged(BundleEvent bundleEvent) { // Parse and createObject metadata when installed Bundle bundle = bundleEvent.getBundle(); if (bundleEvent.getType() == BundleEvent.STARTED) { checkAndLoadBundle(bundle); } else if (bundleEvent.getType() == BundleEvent.STOPPED) { checkAndUnloadBundle(bundle); } }
Example 10
Source File: OSGiActivator.java From sis with Apache License 2.0 | 5 votes |
/** * 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; } } }
Example 11
Source File: Netigso.java From netbeans with Apache License 2.0 | 4 votes |
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); }
Example 12
Source File: MultiListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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"); } // } }
Example 13
Source File: BundleLifecycleHandler.java From ACDD with MIT License | 4 votes |
@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: } }
Example 14
Source File: OSGIServiceLoaderTest.java From incubator-tamaya with Apache License 2.0 | 4 votes |
/** * Test of bundleChanged method, of class OSGIServiceLoader. * * @throws java.lang.Exception */ @Test public void testBundleChanged() throws Exception { //Set up mocks Set<Bundle> resultBundles; MockBundleContext mockBundleContext = new MockBundleContext(); MockBundle startedBundle = new MockBundle(); startedBundle.setState(Bundle.ACTIVE); startedBundle.setBundleId(1); startedBundle.setBundleContext(mockBundleContext); MockBundle stoppedBundle = new MockBundle(); stoppedBundle.setState(Bundle.INSTALLED); stoppedBundle.setBundleId(2); stoppedBundle.setBundleContext(mockBundleContext); MockBundle flipBundle = new MockBundle(); flipBundle.setState(Bundle.INSTALLED); flipBundle.setBundleId(3); flipBundle.setBundleContext(mockBundleContext); mockBundleContext.installBundle(startedBundle); mockBundleContext.installBundle(stoppedBundle); mockBundleContext.installBundle(flipBundle); //Default case mockBundleContext.setServiceCount(0); OSGIServiceLoader instance = new OSGIServiceLoader(mockBundleContext); resultBundles = instance.getResourceBundles(); assertThat(resultBundles).hasSize(1); assertThat(mockBundleContext.getServiceCount()).isEqualTo(2); //After start mockBundleContext.setServiceCount(0); BundleEvent startedEvent = new BundleEvent(BundleEvent.STARTED, flipBundle); instance.bundleChanged(startedEvent); resultBundles = instance.getResourceBundles(); assertThat(resultBundles).hasSize(2); assertThat(mockBundleContext.getServiceCount()).isEqualTo(2); //After stop mockBundleContext.setServiceCount(0); BundleEvent stoppedEvent = new BundleEvent(BundleEvent.STOPPED, flipBundle); instance.bundleChanged(stoppedEvent); resultBundles = instance.getResourceBundles(); assertThat(resultBundles).hasSize(1); assertThat(mockBundleContext.getServiceCount()).isEqualTo(0); }