Java Code Examples for org.osgi.framework.Bundle#getRegisteredServices()
The following examples show how to use
org.osgi.framework.Bundle#getRegisteredServices() .
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: BundleActivatorIntegrationTest.java From vespa with Apache License 2.0 | 6 votes |
@Test public void requireThatBundleActivatorHasAccessToCurrentContainer() throws Exception { TestDriver driver = TestDriver.newSimpleApplicationInstance(); OsgiFramework osgi = driver.osgiFramework(); BundleInstaller installer = new BundleInstaller(driver.osgiFramework()); Bundle bundle = installer.installAndStart("my-bundle-activator.jar").get(0); Class<?> serviceClass = bundle.loadClass("com.yahoo.jdisc.bundle.my_act.MyService"); assertNotNull(serviceClass); BundleContext ctx = osgi.bundleContext(); ServiceReference<?>[] serviceRefs = bundle.getRegisteredServices(); assertEquals(1, serviceRefs.length); ServiceReference<?> serviceRef = serviceRefs[0]; assertNotNull(serviceRef); Object service = ctx.getService(serviceRef); assertNotNull(service); assertTrue(serviceClass.isInstance(service)); assertTrue(driver.close()); }
Example 2
Source File: BundleActivatorIntegrationTest.java From vespa with Apache License 2.0 | 6 votes |
@Test public void requireThatApplicationBundleActivatorHasAccessToCurrentContainer() throws Exception { TestDriver driver = TestDriver.newApplicationBundleInstance("app-g-act.jar", false); OsgiFramework osgi = driver.osgiFramework(); Bundle bundle = osgi.bundles().get(1); Class<?> serviceClass = bundle.loadClass("com.yahoo.jdisc.bundle.g_act.MyService"); assertNotNull(serviceClass); BundleContext ctx = osgi.bundleContext(); ServiceReference<?>[] serviceRefs = bundle.getRegisteredServices(); assertEquals(1, serviceRefs.length); ServiceReference<?> serviceRef = serviceRefs[0]; assertNotNull(serviceRef); Object service = ctx.getService(serviceRef); assertNotNull(service); assertTrue(serviceClass.isInstance(service)); assertTrue(driver.close()); }
Example 3
Source File: Utils.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
public static boolean isAvailable(ServiceReference<?> serviceReference) { Bundle bundle = serviceReference.getBundle(); if (bundle == null) { return false; } for (ServiceReference<?> registeredService : bundle.getRegisteredServices()) { if (registeredService.equals(serviceReference)) { return true; } } return false; }