org.osgi.framework.BundleEvent Java Examples
The following examples show how to use
org.osgi.framework.BundleEvent.
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: Framework.java From ACDD with MIT License | 6 votes |
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(); } } }
Example #2
Source File: Spin.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
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(); }
Example #3
Source File: SCR.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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(); } }
Example #4
Source File: ResourceBundleTracker.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public synchronized void removedBundle(Bundle bundle, BundleEvent event, Object object) { LanguageResourceBundleManager languageResource = this.bundleLanguageResourceMap.remove(bundle); if (languageResource != null) { languageResource.clearCache(); } if (isFragmentBundle(bundle)) { List<Bundle> hosts = returnHostBundles(bundle); for (Bundle host : hosts) { this.bundleLanguageResourceMap.remove(host); addResourceBundle(host); } } else { this.bundleLanguageResourceMap.remove(bundle); } }
Example #5
Source File: LargeIconsDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void bundleChanged(final BundleEvent ev) { super.bundleChanged(ev); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { for (final JComponent jComponent : components) { final JLargeIcons comp = (JLargeIcons) jComponent; switch(ev.getType()) { case BundleEvent.INSTALLED: comp.addBundle(new Bundle[]{ev.getBundle()}); break; case BundleEvent.UNINSTALLED: comp.removeBundle(ev.getBundle()); break; default: comp.updateBundleComp(ev.getBundle()); break; } } repaintComponents(); } }); }
Example #6
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 #7
Source File: BundleImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Set state to INSTALLED and throw away our classloader. Reset all package * registration. We assume that the bundle is resolved when entering this * method. */ void setStateInstalled(boolean sendEvent) { synchronized (fwCtx.resolver) { // Make sure that bundleContext is invalid if (bundleContext != null) { bundleContext.invalidate(); bundleContext = null; } final BundleGeneration current = current(); if (current.isFragment()) { current.fragment.removeHost(null); } else { current.closeClassLoader(); current.unregisterPackages(true); current.bpkgs.registerPackages(); } current.clearWiring(); state = INSTALLED; if (sendEvent) { operation = UNRESOLVING; bundleThread().bundleChanged(new BundleEvent(BundleEvent.UNRESOLVED, this)); } operation = IDLE; } }
Example #8
Source File: ModelPackageBundleListener.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 6 votes |
@Override public void removedBundle(Bundle bundle, BundleEvent event, ServiceRegistration[] object) { for (ServiceRegistration reg : object) { ServiceReference ref = reg.getReference(); String[] adapterTypeNames = PropertiesUtil.toStringArray(ref.getProperty(AdapterFactory.ADAPTER_CLASSES)); if (adapterTypeNames != null) { String implTypeName = PropertiesUtil.toString(ref.getProperty(PROP_IMPLEMENTATION_CLASS), null); for (String adapterTypeName : adapterTypeNames) { adapterImplementations.remove(adapterTypeName, implTypeName); } } reg.unregister(); } adapterImplementations.removeResourceTypeBindings(bundle); }
Example #9
Source File: ManagementPermissionsAdder.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@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); } }
Example #10
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 #11
Source File: AutomationResourceBundlesEventQueue.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
/** * This method is responsible for initializing the queue with all already received BundleEvents and starting a * thread that should process them. * * @param queue list with all already received BundleEvents */ protected synchronized void addAll(List<BundleEvent> queue) { if (closed) { return; } if (shared) { this.queue = new LinkedList<>(); shared = false; } if (this.queue.addAll(queue)) { if (running) { notifyAll(); } else { runningThread = new Thread(this, "Automation Provider Processing Queue"); runningThread.start(); running = true; } } }
Example #12
Source File: JspBundleCustomizer.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
@Override public JspBundle addingBundle ( final Bundle bundle, final BundleEvent event ) { final Enumeration<String> result = bundle.getEntryPaths ( "/WEB-INF" ); if ( result != null && result.hasMoreElements () ) { try { return new JspBundle ( bundle, this.service, this.context ); } catch ( ServletException | NamespaceException e ) { logger.warn ( "Failed to register JSP bundle: " + bundle.getSymbolicName (), e ); return null; } } return null; }
Example #13
Source File: BundleImpl.java From ACDD with MIT License | 6 votes |
BundleImpl(File file) throws Exception { long currentTimeMillis = System.currentTimeMillis(); DataInputStream dataInputStream = new DataInputStream(new FileInputStream(new File(file, "meta"))); this.location = dataInputStream.readUTF(); this.currentStartlevel = dataInputStream.readInt(); this.persistently = dataInputStream.readBoolean(); dataInputStream.close(); this.bundleDir = file; this.state = BundleEvent.STARTED; try { this.archive = new BundleArchive(this.location, file); resolveBundle(false); Framework.bundles.put(this.location, this); Framework.notifyBundleListeners(1, this); if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) { log.info("Framework: Bundle " + toString() + " loaded. " + (System.currentTimeMillis() - currentTimeMillis) + " ms"); } } catch (Exception e) { throw new BundleException("Could not load bundle " + this.location, e.getCause()); } }
Example #14
Source File: AutomationResourceBundlesEventQueue.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
/** * This method is called when a new event for a bundle providing automation resources is received. It causes a * creation of a new thread if there is no other created yet and starting the it. If the thread already exists, * it is waiting for events and will be notified for the event. * * @param bundle providing automation resources * @param event for a bundle tracked by the {@code BundleTracker}. It has been for adding, modifying or removing the * bundle. */ protected synchronized void addEvent(Bundle bundle, BundleEvent event) { if (closed) { return; } if (shared) { queue = new LinkedList<>(); shared = false; } if (queue.add(event)) { logger.debug("Process bundle event {}, for automation bundle '{}' ", event.getType(), event.getBundle().getSymbolicName()); if (running) { notifyAll(); } else { runningThread = new Thread(this, "Automation Provider Processing Queue"); runningThread.start(); running = true; } } }
Example #15
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 #16
Source File: Framework.java From ACDD with MIT License | 5 votes |
@Override public int getBundleStartLevel(Bundle bundle) { if (bundle == this) { return 0; } BundleImpl bundleImpl = (BundleImpl) bundle; if (bundleImpl.state != BundleEvent.INSTALLED) { return bundleImpl.currentStartlevel; } throw new IllegalArgumentException("Bundle " + bundle + " has been uninstalled"); }
Example #17
Source File: BundleLifecycleHandler.java From AtlasForAndroid with MIT License | 5 votes |
@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: } }
Example #18
Source File: Activator.java From logging-log4j2 with Apache License 2.0 | 5 votes |
@Override public void bundleChanged(final BundleEvent event) { switch (event.getType()) { case BundleEvent.STARTED: loadProvider(event.getBundle()); unlockIfReady(); break; default: break; } }
Example #19
Source File: DefaultSwingBundleDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void bundleChanged(BundleEvent ev) { if (!bAlive) { return; } if (bUpdateOnBundleChange) { updateComponents(Activator.desktop.getSelectedBundles()); } }
Example #20
Source File: BundleImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
void startFailed() { // 8: state = STOPPING; fwCtx.listeners.bundleChanged(new BundleEvent(BundleEvent.STOPPING, this)); removeBundleResources(); bundleContext.invalidate(); bundleContext = null; state = RESOLVED; fwCtx.listeners.bundleChanged(new BundleEvent(BundleEvent.STOPPED, this)); }
Example #21
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 #22
Source File: AutomationResourceBundlesTracker.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * A bundle tracked by the {@code BundleTracker} has been removed. * * <p> * This method is called after a bundle is no longer being tracked by the {@code BundleTracker}. * * @param bundle The {@code Bundle} that has been removed. * @param event The bundle event which caused this customizer method to be * called or {@code null} if there is no bundle event associated with * the call to this method. * @param object The tracked object for the specified bundle. */ @Override public void removedBundle(Bundle bundle, BundleEvent event, Bundle object) { if (HostFragmentMappingUtil.isFragmentBundle(bundle)) { for (Entry<Bundle, List<Bundle>> entry : HostFragmentMappingUtil.getMapping()) { if (entry.getValue().contains(bundle)) { Bundle host = entry.getKey(); addEvent(host, new BundleEvent(BundleEvent.UPDATED, host)); } } } else { addEvent(bundle, event); } }
Example #23
Source File: TemplateTrackerTest.java From wisdom with Apache License 2.0 | 5 votes |
@Test public void testDynamism() throws MalformedURLException { TemplateTracker tracker = new TemplateTracker(); tracker.context = mock(BundleContext.class); tracker.engine = mock(ThymeleafTemplateCollector.class); when(tracker.engine.extension()).thenReturn(ThymeleafTemplateCollector.THYMELEAF_TEMPLATE_EXTENSION); Bundle bundle = mock(Bundle.class); // Test on empty bundle. when(bundle.findEntries(anyString(), anyString(), anyBoolean())).thenReturn(null); assertThat(tracker.addingBundle(bundle, new BundleEvent(BundleEvent.STARTED, bundle))).isEmpty(); // Verify no call verify(tracker.engine, never()).addTemplate(any(Bundle.class), any(URL.class)); // New bundle with a template inside. File file = new File("src/test/resources/templates/javascript.thl.html"); Vector<URL> v = new Vector<URL>(); v.add(file.toURI().toURL()); when(bundle.findEntries(anyString(), anyString(), anyBoolean())).thenReturn(v.elements()); List<ThymeLeafTemplateImplementation> list = tracker.addingBundle(bundle, new BundleEvent(BundleEvent.STARTED, bundle)); assertThat(list).isNotNull(); assertThat(list).hasSize(1); verify(tracker.engine, times(1)).addTemplate(bundle, file.toURI().toURL()); tracker.modifiedBundle(bundle, null, list); verify(tracker.engine, times(1)).updatedTemplate(); list.clear(); list.add(mock(ThymeLeafTemplateImplementation.class)); tracker.removedBundle(bundle, null, list); verify(tracker.engine, times(1)).deleteTemplate(any(ThymeLeafTemplateImplementation.class)); }
Example #24
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); } }
Example #25
Source File: DelayedProbeInvokerFactory.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Workaround https://issues.apache.org/jira/browse/KARAF-4899 by * re-adding probe bundle to root region before any service lookup * (avoids spurious service lookup issues due to region filtering) */ private void installRegionWorkaround(final BundleContext context) { Map<String, ?> maxRanking = singletonMap(SERVICE_RANKING, Integer.MAX_VALUE); // add probe to root region on install context.registerService(EventHook.class, (event, contexts) -> { if (event.getType() == BundleEvent.INSTALLED) { fixProbeRegion(event.getBundle()); } }, new Hashtable<>(maxRanking)); // add probe to root region whenever a service it's listening to changes context.registerService(EventListenerHook.class, (event, listeners) -> { if (((String[]) event.getServiceReference().getProperty(Constants.OBJECTCLASS))[0].contains("pax.exam")) { listeners.keySet().stream().map(BundleContext::getBundle).forEach(this::fixProbeRegion); } }, new Hashtable<>(maxRanking)); // add probe to root region whenever it's directly looking up a service context.registerService(FindHook.class, (findContext, name, filter, allServices, references) -> { if ((name != null && name.contains("pax.exam")) || (filter != null && filter.contains("pax.exam"))) { fixProbeRegion(findContext.getBundle()); } }, new Hashtable<>(maxRanking)); }
Example #26
Source File: I18NControllerTest.java From wisdom with Apache License 2.0 | 5 votes |
@Before public void setUp() { InternationalizationServiceSingleton service = new InternationalizationServiceSingleton(null); final Bundle bundle = InternationalizationServiceSingletonTest.getMockBundle(); service.addingBundle(bundle, new BundleEvent(BundleEvent.STARTED, bundle)); controller = new I18nController(); controller.service = service; final JacksonSingleton jacksonSingleton = new JacksonSingleton(); jacksonSingleton.validate(); controller.json = jacksonSingleton; }
Example #27
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 #28
Source File: SecurePermissionOps.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override void callBundleChanged(final FrameworkContext fwCtx, final BundleEvent evt) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { fwCtx.listeners.bundleChanged(evt); return null; } }); }
Example #29
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 #30
Source File: JRxmlFileBundleListener.java From carbon-commons with Apache License 2.0 | 5 votes |
public void bundleChanged(BundleEvent bundleEvent) { Bundle bundle = bundleEvent.getBundle(); try { if (bundleEvent.getType() == BundleEvent.STARTED) { addJrXmlToRegistry(bundle); } } catch (Exception e) { log.error("Error occurred when putting jrXml file to registry in bundle " + bundle.getSymbolicName(), e); } }