org.osgi.framework.BundleListener Java Examples
The following examples show how to use
org.osgi.framework.BundleListener.
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: EmacsPlusActivator.java From e4macs with Eclipse Public License 1.0 | 6 votes |
private void addBundlerListener(BundleContext context) { // Listen for our STARTED event // Alternatively, we can get the bundle from org.osgi.framework.FrameworkUtil context.addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { String name = event.getBundle().getSymbolicName(); if (name != null && name.equals(PLUGIN_ID)) { switch (event.getType()) { case BundleEvent.STARTED: bundleStarted(); break; case BundleEvent.UNINSTALLED: emacsIds = null; break; default: break; } } } }); }
Example #2
Source File: Framework.java From AtlasForAndroid with MIT License | 6 votes |
static void notifyBundleListeners(int i, Bundle bundle) { int i2 = 0; if (!syncBundleListeners.isEmpty() || !bundleListeners.isEmpty()) { BundleEvent bundleEvent = new BundleEvent(i, bundle); BundleListener[] bundleListenerArr = (BundleListener[]) syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]); for (BundleListener bundleChanged : bundleListenerArr) { bundleChanged.bundleChanged(bundleEvent); } if (!bundleListeners.isEmpty()) { bundleListenerArr = (BundleListener[]) bundleListeners.toArray(new BundleListener[bundleListeners.size()]); while (i2 < bundleListenerArr.length) { bundleListenerArr[i2].bundleChanged(bundleEvent); i2++; } } } }
Example #3
Source File: OSGiInjectionTest.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 6 votes |
@Test public void testSetOSGiModelField() throws Exception { ServiceReference ref1 = mock(ServiceReference.class); ServiceInterface service1 = mock(ServiceInterface.class); when(bundleContext.getService(ref1)).thenReturn(service1); ServiceReference ref2 = mock(ServiceReference.class); ServiceInterface service2 = mock(ServiceInterface.class); when(bundleContext.getService(ref2)).thenReturn(service2); when(bundleContext.getServiceReferences(ServiceInterface.class.getName(), null)).thenReturn( new ServiceReference[] { ref1, ref2 }); Resource res = mock(Resource.class); SetOSGiModel model = factory.getAdapter(res, SetOSGiModel.class); assertNull(model); verify(bundleContext).registerService(eq(Runnable.class), eq(factory), any(Dictionary.class)); verify(bundleContext).addBundleListener(any(BundleListener.class)); verify(bundleContext).registerService(eq(Object.class), any(Object.class), any(Dictionary.class)); verify(bundleContext).getBundles(); verify(bundleContext).getBundle(); verifyNoMoreInteractions(res, bundleContext); }
Example #4
Source File: Framework.java From ACDD with MIT License | 6 votes |
static void notifyBundleListeners(int event, Bundle bundle) { if (!syncBundleListeners.isEmpty() || !bundleListeners.isEmpty()) { BundleEvent bundleEvent = new BundleEvent(event, bundle); BundleListener[] bundleListenerArr = syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]); for (BundleListener bundleChanged : bundleListenerArr) { bundleChanged.bundleChanged(bundleEvent); } if (!bundleListeners.isEmpty()) { bundleListenerArr = bundleListeners.toArray(new BundleListener[bundleListeners.size()]); for (BundleListener bundleListener : bundleListenerArr) { bundleListener.bundleChanged(bundleEvent); } } } }
Example #5
Source File: Test7.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public boolean runTest() { BundleListener[] listeners = new BundleListener[NUM_LISTENERS]; for (int i = 0; i < NUM_LISTENERS; i++) { listeners[i] = new MyBundleListener(); bc.addBundleListener(listeners[i]); } try { bundle.stop(); bundle.start(); } catch (BundleException e) { return false; } for (int i = 0; i < NUM_LISTENERS; i++) { bc.removeBundleListener(listeners[i]); } return true; }
Example #6
Source File: BundleGetEntryTest.java From concierge with Eclipse Public License 1.0 | 6 votes |
@Test public void testGetEntryFromBundleListenerResolverEvent() throws Exception { SyntheticBundleBuilder builder = SyntheticBundleBuilder.newBuilder(); builder.bundleSymbolicName("bundle"); builder.addFile("plugin.properties", "# props"); // register a bundle listener framework.getBundleContext().addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.RESOLVED) { // get resources from bundle URL res1 = event.getBundle().getEntry("/plugin.properties"); Assert.assertNotNull(res1); Assert.assertEquals("# props", TestUtils.getContentFromUrl(res1)); } } }); // now trigger install bundleUnderTest = installBundle(builder); }
Example #7
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * add a bundle listener. * * @param listener * a bundle listener. * @see org.osgi.framework.BundleContext#addBundleListener(org.osgi.framework.BundleListener) */ public void addBundleListener(final BundleListener listener) { checkValid(); final List<BundleListener> registered = bundleListenerMap.get(this); if (registered == null || !registered.contains(listener)) { if (listener instanceof SynchronousBundleListener) { syncBundleListeners .add((SynchronousBundleListener) listener); } else { bundleListeners.add(listener); } bundleListenerMap.insert(this, listener); } }
Example #8
Source File: BundleGetEntryTest.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * This test will add a bundle listener to framework. Within bundle listener * it tries to read a resource from bundle when bundle event indicates * bundle has been INSTALLED. This is typically used in an extender pattern. */ @Test //@Ignore("Does not work. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=467160") public void testGetEntryFromBundleListenerInstalledEvent() throws Exception { SyntheticBundleBuilder builder = SyntheticBundleBuilder.newBuilder(); builder.bundleSymbolicName("bundle"); builder.addFile("plugin.properties", "# props"); // register a bundle listener framework.getBundleContext().addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.INSTALLED) { // get resources from bundle URL res1 = event.getBundle().getEntry("/plugin.properties"); Assert.assertNotNull(res1); Assert.assertEquals("# props", TestUtils.getContentFromUrl(res1)); } } }); // now trigger install bundleUnderTest = installBundle(builder); }
Example #9
Source File: Listeners.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add a bundle listener to the current framework. * * @param bundle Who wants to add listener. * @param listener Object to add. */ void addBundleListener(BundleContextImpl bc, BundleListener listener) { final ListenerEntry le = new ListenerEntry(bc, listener); if (listener instanceof SynchronousBundleListener) { secure.checkListenerAdminPerm(bc.bundle); synchronized (syncBundleListeners) { syncBundleListeners.add(le); } } else { synchronized (bundleListeners) { bundleListeners.add(le); } } }
Example #10
Source File: BundleContextImpl.java From AtlasForAndroid with MIT License | 5 votes |
public void removeBundleListener(BundleListener bundleListener) { checkValid(); (bundleListener instanceof SynchronousBundleListener ? Framework.syncBundleListeners : Framework.bundleListeners).remove(bundleListener); this.bundle.registeredBundleListeners.remove(bundleListener); if (this.bundle.registeredBundleListeners.isEmpty()) { this.bundle.registeredBundleListeners = null; } }
Example #11
Source File: BundleContextImpl.java From AtlasForAndroid with MIT License | 5 votes |
public void addBundleListener(BundleListener bundleListener) { checkValid(); List list = bundleListener instanceof SynchronousBundleListener ? Framework.syncBundleListeners : Framework.bundleListeners; if (this.bundle.registeredBundleListeners == null) { this.bundle.registeredBundleListeners = new ArrayList(); } if (!this.bundle.registeredBundleListeners.contains(bundleListener)) { list.add(bundleListener); this.bundle.registeredBundleListeners.add(bundleListener); } }
Example #12
Source File: Listeners.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * */ private void bundleChanged(final ListenerEntry le, final BundleEvent evt) { try { ((BundleListener)le.listener).bundleChanged(evt); } catch (final Throwable pe) { fwCtx.frameworkError(le.bc, pe); } }
Example #13
Source File: Listeners.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Remove bundle listener from current framework. Silently ignore * if listener doesn't exist. If listener is registered more than * once remove one instances. * * @param bundle Who wants to remove listener. * @param listener Object to remove. */ void removeBundleListener(BundleContextImpl bc, BundleListener listener) { final ListenerEntry le = new ListenerEntry(bc, listener); if (listener instanceof SynchronousBundleListener) { synchronized (syncBundleListeners) { secure.checkListenerAdminPerm(bc.bundle); syncBundleListeners.remove(le); } } else { synchronized (bundleListeners) { bundleListeners.remove(le); } } }
Example #14
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * clear all traces of a bundle. * * @param bundle * the bundle. */ void clearBundleTrace(final AbstractBundle bundle) { // remove all registered listeners if (bundle.registeredFrameworkListeners != null) { frameworkListeners.removeAll(bundle.registeredFrameworkListeners); bundle.registeredFrameworkListeners = null; } if (bundle.registeredServiceListeners != null) { serviceListeners.removeAll(bundle.registeredServiceListeners); bundle.registeredServiceListeners = null; } final List<BundleListener> bundleListeners = bundleListenerMap .get(bundle.context); if (bundleListeners != null) { bundleListeners.removeAll(bundleListeners); syncBundleListeners.removeAll(bundleListeners); bundleListenerMap.remove(bundle.context); } // unregister registered services final ServiceReference<?>[] regs = bundle.getRegisteredServices(); if (regs != null) { for (int i = 0; i < regs.length; i++) { unregisterService(regs[i]); ((ServiceReferenceImpl<?>) regs[i]).invalidate(); } bundle.registeredServices = null; } // unget all using services final ServiceReference<?>[] refs = bundle.getServicesInUse(); if (refs != null) { for (int i = 0; i < refs.length; i++) { ServiceReferenceImpl<?> ref = ((ServiceReferenceImpl<?>) refs[i]); ref.ungetAllServices(bundle); } } }
Example #15
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * remove a bundle listener. * * @param listener * a bundle listener. * @see org.osgi.framework.BundleContext#removeBundleListener(org.osgi.framework.BundleListener) * */ public void removeBundleListener(final BundleListener listener) { checkValid(); if (bundle == Concierge.this) { return; } (listener instanceof SynchronousBundleListener ? syncBundleListeners : bundleListeners).remove(listener); bundleListenerMap.remove(this, listener); }
Example #16
Source File: EclipseClassProvider.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * 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); }
Example #17
Source File: NetigsoSelfQueryTest.java From netbeans with Apache License 2.0 | 4 votes |
public void addBundleListener(BundleListener bl) { }
Example #18
Source File: MockBundleContext.java From incubator-tamaya with Apache License 2.0 | 4 votes |
@Override public void removeBundleListener(BundleListener bl) { bundleListenersCount--; }
Example #19
Source File: MockBundleContext.java From incubator-tamaya with Apache License 2.0 | 4 votes |
@Override public void addBundleListener(BundleListener bl) { bundleListenersCount++; }
Example #20
Source File: Framework.java From AtlasForAndroid with MIT License | 4 votes |
static void removeBundleListener(BundleListener bundleListener) { bundleListeners.remove(bundleListener); }
Example #21
Source File: Framework.java From AtlasForAndroid with MIT License | 4 votes |
static void addBundleListener(BundleListener bundleListener) { bundleListeners.add(bundleListener); }
Example #22
Source File: NetigsoSelfQueryTest.java From netbeans with Apache License 2.0 | 4 votes |
public void removeBundleListener(BundleListener bl) { }
Example #23
Source File: Netbinox.java From netbeans with Apache License 2.0 | 4 votes |
public void removeBundleListener(BundleListener bl) { delegate.removeBundleListener(bl); }
Example #24
Source File: Netbinox.java From netbeans with Apache License 2.0 | 4 votes |
public void addBundleListener(BundleListener bl) { delegate.addBundleListener(bl); }
Example #25
Source File: Atlas.java From AtlasForAndroid with MIT License | 4 votes |
public void removeBundleListener(BundleListener bundleListener) { Framework.removeBundleListener(bundleListener); }
Example #26
Source File: Atlas.java From AtlasForAndroid with MIT License | 4 votes |
public void addBundleListener(BundleListener bundleListener) { Framework.addBundleListener(bundleListener); }
Example #27
Source File: Framework.java From ACDD with MIT License | 4 votes |
static void removeBundleListener(BundleListener bundleListener) { bundleListeners.remove(bundleListener); }
Example #28
Source File: Framework.java From ACDD with MIT License | 4 votes |
static void addBundleListener(BundleListener bundleListener) { bundleListeners.add(bundleListener); }
Example #29
Source File: OpenAtlas.java From ACDD with MIT License | 4 votes |
public void removeBundleListener(BundleListener bundleListener) { Framework.removeBundleListener(bundleListener); }
Example #30
Source File: OpenAtlas.java From ACDD with MIT License | 4 votes |
public void addBundleListener(BundleListener bundleListener) { Framework.addBundleListener(bundleListener); }