org.osgi.framework.ServiceReference Java Examples
The following examples show how to use
org.osgi.framework.ServiceReference.
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: BluetoothImporter.java From fuchsia with Apache License 2.0 | 6 votes |
@Bind(aggregate = true, optional = true, filter = "(protocol=bluetooth)") public void bindBluetoothProxyFactories(Factory f, ServiceReference<Factory> sr) { LOG.warn("Found one factory : " + f.getName()); String friendlyName = (String) sr.getProperty("device_name"); if (friendlyName == null) { return; } bluetoothProxiesFactories.put(friendlyName, f); Map.Entry<String, ImportDeclaration> unresolvedImportDeclaration; ImportDeclaration iDec = null; String fn = null; Iterator<Map.Entry<String, ImportDeclaration>> iterator = unresolvedImportDeclarations.entrySet().iterator(); while (iterator.hasNext()) { unresolvedImportDeclaration = iterator.next(); fn = unresolvedImportDeclaration.getKey(); if (fn.startsWith(friendlyName)) { iDec = unresolvedImportDeclaration.getValue(); ComponentInstance proxy = createProxy(iDec, f); iDec.handle(this.serviceReference); iterator.remove(); resolvedImportDeclarations.put(fn, iDec); proxyComponentInstances.put(iDec, proxy); } } }
Example #2
Source File: CommandTty.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public CommandProcessor addingService(ServiceReference<CommandProcessor> reference) { final CommandProcessor cmdProcessor = bc.getService(reference); try { closeSession(); commandSession = cmdProcessor.createSession(inStream, outStream, errStream); readThread = new ReadThread(inStream, commandSession); readThread.start(); } catch (Exception ioe) { log(LogService.LOG_ERROR, "Failed to start command session, can not continue"); } return cmdProcessor; }
Example #3
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
public static String getRelativeUrl() { BundleContext context = CarbonUIUtil.getBundleContext(); ServiceReference reference = context.getServiceReference(RegistryService.class.getName()); RegistryService registryService = (RegistryService) context.getService(reference); String url = null; try { Registry systemRegistry = registryService.getConfigSystemRegistry(); Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS); String servicePath = resource.getProperty("service-path"); String contextRoot = resource.getProperty("context-root"); contextRoot = contextRoot.equals("/") ? "" : contextRoot; url = contextRoot + servicePath + "/WSDL2CodeService"; } catch (Exception e) { log.error(e); } return url; }
Example #4
Source File: JQueryOperationsImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
public TypeLocationService getTypeLocationService() { if (typeLocationService == null) { // Get all Services implement TypeLocationService interface try { ServiceReference<?>[] references = this.context .getAllServiceReferences( TypeLocationService.class.getName(), null); for (ServiceReference<?> ref : references) { return (TypeLocationService) this.context.getService(ref); } return null; } catch (InvalidSyntaxException e) { LOGGER.warning("Cannot load TypeLocationService on JQueryOperationsImpl."); return null; } } else { return typeLocationService; } }
Example #5
Source File: OsgiComponentServiceTest.java From components with Apache License 2.0 | 6 votes |
@Test public void testRegistryServiceDynamicLoadOfComponent() throws BundleException, MalformedURLException, URISyntaxException { // inside eclipse the bundle context can be retrieved from the Activator.start method or using the FrameworkUtil // class. BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext(); ServiceReference<DefinitionRegistryService> compServiceRef = bundleContext .getServiceReference(DefinitionRegistryService.class); if (compServiceRef != null) { DefinitionRegistryService defService = bundleContext.getService(compServiceRef); assertNotNull(defService); assertEquals(0, defService.getDefinitionsMapByType(Definition.class).size()); installNewComponentBundle(bundleContext); assertEquals(1, defService.getDefinitionsMapByType(Definition.class).size()); } else { fail("Failed to retrieve the Component service"); } }
Example #6
Source File: DependencyListenerImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
public GeoOperations getGeoOperations() { if (operations == null) { // Get all Services implement GeoOperations interface try { ServiceReference[] references = context .getAllServiceReferences(GeoOperations.class.getName(), null); for (ServiceReference ref : references) { operations = (GeoOperations) context.getService(ref); return operations; } return null; } catch (InvalidSyntaxException e) { LOGGER.warning("Cannot load GeoOperations on DependencyListenerImpl."); return null; } } else { return operations; } }
Example #7
Source File: DatatablesOperationsImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
public ProjectOperations getProjectOperations() { if (projectOperations == null) { // Get all Services implement WebMetadataService interface try { ServiceReference<?>[] references = this.context .getAllServiceReferences( ProjectOperations.class.getName(), null); for (ServiceReference<?> ref : references) { return (ProjectOperations) this.context.getService(ref); } return null; } catch (InvalidSyntaxException e) { LOGGER.warning("Cannot load ProjectOperations on DatatablesOperationsImpl."); return null; } } else { return projectOperations; } }
Example #8
Source File: OSGIServiceContext.java From incubator-tamaya with Apache License 2.0 | 6 votes |
@Override public <T> T create(Class<T> serviceType, Supplier<T> supplier) { LOG.finest("TAMAYA Creating service: " + serviceType.getName()); ServiceReference<T> ref = this.osgiServiceLoader.getBundleContext().getServiceReference(serviceType); if(ref!=null){ try { return (T)this.osgiServiceLoader.getBundleContext().getService(ref).getClass().getConstructor() .newInstance(); } catch (Exception e) { if(supplier!=null){ return supplier.get(); } return null; } } if(supplier!=null){ return supplier.get(); } return null; }
Example #9
Source File: FelixGoPluginOSGiFrameworkIntegrationTest.java From gocd with Apache License 2.0 | 6 votes |
@Test void shouldLoadAValidPluginWithMultipleExtensions_ImplementingDifferentExtensions() throws Exception { final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor("valid-plugin-with-multiple-extensions", validMultipleExtensionPluginBundleDir)); registry.loadPlugin(bundleDescriptor); Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor); assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE); BundleContext context = bundle.getBundleContext(); String taskExtensionFilter = String.format("(&(%s=%s)(%s=%s))", "PLUGIN_ID", "valid-plugin-with-multiple-extensions", Constants.BUNDLE_CATEGORY, "task"); String analyticsExtensionFilter = String.format("(&(%s=%s)(%s=%s))", "PLUGIN_ID", "valid-plugin-with-multiple-extensions", Constants.BUNDLE_CATEGORY, "analytics"); ServiceReference<?>[] taskExtensionServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), taskExtensionFilter); assertThat(taskExtensionServiceReferences.length).isEqualTo(1); assertThat(((GoPlugin) context.getService(taskExtensionServiceReferences[0])).pluginIdentifier().getExtension()).isEqualTo("task"); ServiceReference<?>[] analyticsExtensionServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), analyticsExtensionFilter); assertThat(analyticsExtensionServiceReferences.length).isEqualTo(1); assertThat(((GoPlugin) context.getService(analyticsExtensionServiceReferences[0])).pluginIdentifier().getExtension()).isEqualTo("analytics"); }
Example #10
Source File: CXFController.java From cxf with Apache License 2.0 | 6 votes |
public List<Bus> getBusses() { List<Bus> busses = new ArrayList<>(); try { Collection<ServiceReference<Bus>> references = bundleContext.getServiceReferences(Bus.class, null); if (references != null) { for (ServiceReference<Bus> reference : references) { if (reference != null) { Bus bus = bundleContext.getService(reference); if (bus != null) { busses.add(bus); } } } } } catch (Exception e) { LOG.log(Level.INFO, "Cannot retrieve the list of CXF Busses.", e); } return busses; }
Example #11
Source File: Activator.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@Override public void start ( final BundleContext context ) throws Exception { this.scheduler = Executors.newSingleThreadScheduledExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) ); final String driver = DataSourceHelper.getDriver ( DS_PREFIX, DataSourceHelper.DEFAULT_PREFIX ); if ( driver == null ) { logger.error ( "JDBC driver is not set" ); throw new IllegalStateException ( "JDBC driver name is not set" ); } this.dataSourceFactoryTracker = new DataSourceFactoryTracker ( context, driver, new SingleServiceListener<DataSourceFactory> () { @Override public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service ) { unregister (); if ( service != null ) { register ( service, context ); } } } ); this.dataSourceFactoryTracker.open ( true ); }
Example #12
Source File: DefaultServiceDirectory.java From onos with Apache License 2.0 | 6 votes |
/** * Returns the reference to the implementation of the specified service. * * @param serviceClass service class * @param <T> type of service * @return service implementation */ public static <T> T getService(Class<T> serviceClass) { Bundle bundle = FrameworkUtil.getBundle(serviceClass); if (bundle != null) { BundleContext bc = bundle.getBundleContext(); if (bc != null) { ServiceReference<T> reference = bc.getServiceReference(serviceClass); if (reference != null) { T impl = bc.getService(reference); if (impl != null) { return impl; } } } } throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found"); }
Example #13
Source File: JpaGeoOperationsImpl.java From gvnix with GNU General Public License v3.0 | 6 votes |
public FileManager getFileManager() { if (fileManager == null) { // Get all Services implement FileManager interface try { ServiceReference<?>[] references = this.context .getAllServiceReferences(FileManager.class.getName(), null); for (ServiceReference<?> ref : references) { return (FileManager) this.context.getService(ref); } return null; } catch (InvalidSyntaxException e) { LOGGER.warning("Cannot load FileManager on JpaGeoOperationsImpl."); return null; } } else { return fileManager; } }
Example #14
Source File: HttpServiceUtilTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldReturnHttpServicePortFromSystemProperty() throws InvalidSyntaxException { when(bundleContext.getAllServiceReferences(ORG_OSGI_SERVICE_HTTP_SERVICE, null)) .thenReturn(new ServiceReference[0]); when(bundleContext.getProperty(HTTP_PORT)).thenReturn("9090"); int port = HttpServiceUtil.getHttpServicePort(bundleContext); assertThat(port, is(9090)); }
Example #15
Source File: MultiListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public LogReaderService addingService(ServiceReference<LogReaderService> sr) { LogReaderService logReader = (LogReaderService) Activator.bc.getService(sr); if (logReader != null) { logReader.addLogListener(MultiListener.this); } return logReader; }
Example #16
Source File: Activator.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * (non-Javadoc). * @param reference * the reference * @return the object * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference) */ public Object addingService(ServiceReference reference) { Converter converter = (Converter) bundleContext.getService(reference); Converter xliff2Inx = new Xliff2OpenOffice(converter); Properties properties = new Properties(); properties.put(Converter.ATTR_NAME, Xliff2OpenOffice.NAME_VALUE); properties.put(Converter.ATTR_TYPE, Xliff2OpenOffice.TYPE_VALUE); properties.put(Converter.ATTR_TYPE_NAME, Xliff2OpenOffice.TYPE_NAME_VALUE); ServiceRegistration registration = ConverterRegister.registerReverseConverter(bundleContext, xliff2Inx, properties); return registration; }
Example #17
Source File: StatusTest.java From fuchsia with Apache License 2.0 | 5 votes |
@Test public void testCreationBound() throws Exception { Set<ServiceReference> set = new HashSet<ServiceReference>(); set.add(mock(ServiceReference.class)); set.add(mock(ServiceReference.class)); Status status = Status.from(set, Collections.<ServiceReference>emptySet()); assertThat(status.isBound()).isEqualTo(true); assertThat(status.isHandled()).isEqualTo(false); assertThat(status.getServiceReferencesBounded().size()).isEqualTo(2); assertThat(status.getServiceReferencesHandled().size()).isEqualTo(0); }
Example #18
Source File: TypicalsecurityOperationsImpl.java From gvnix with GNU General Public License v3.0 | 5 votes |
public WebProjectUtils getWebPojectUtils() { if (webProjectUtils == null) { // Get all Services implement WebProjectUtils interface try { ServiceReference<?>[] references = this.context .getAllServiceReferences( WebProjectUtils.class.getName(), null); for (ServiceReference<?> ref : references) { webProjectUtils = (WebProjectUtils) this.context .getService(ref); return webProjectUtils; } return null; } catch (InvalidSyntaxException e) { LOGGER.warning("Cannot load WebProjectUtils on TypicalSecurityOperationsImpl."); return null; } } else { return webProjectUtils; } }
Example #19
Source File: ServiceRepresentationList.java From concierge with Eclipse Public License 1.0 | 5 votes |
public ServiceRepresentationList(ServiceReference<?>[] srefs) { if (srefs != null) { for (final ServiceReference<?> sref : srefs) { add(new ServicePojo(sref)); } } }
Example #20
Source File: HiveImpl.java From neoscada with Eclipse Public License 1.0 | 5 votes |
public synchronized void removeItem ( final ServiceReference<?> serviceReference ) { logger.info ( "Removing {}", serviceReference ); this.context.ungetService ( serviceReference ); final ItemDescriptor descriptor = this.items.remove ( serviceReference ); this.storage.removed ( descriptor ); unregisterItem ( descriptor.getItem () ); }
Example #21
Source File: LogEntryImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public LogEntryImpl(final Bundle bc, final ServiceReference<?> sd, final int l, final String m, final Throwable e) { this.bundle = bc; this.sr = sd; this.level = l; this.msg = m; this.e = e; this.millis = System.currentTimeMillis(); }
Example #22
Source File: ServiceDiscoverer.java From neoscada with Eclipse Public License 1.0 | 5 votes |
private void addReference ( final ServiceReference<?> ref ) { logger.info ( "Adding service: {}", ref ); if ( this.references.add ( ref ) ) { update (); } }
Example #23
Source File: ShellActivator.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * called, when the bundle is started. * * @param context * the bundle context. * * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ public void start(final BundleContext context) throws Exception { ShellActivator.context = context; List<ShellCommandGroup> plugins = new ArrayList<ShellCommandGroup>(); final ServiceReference<?> pkgAdminRef = context .getServiceReference("org.osgi.service.packageadmin.PackageAdmin"); if (pkgAdminRef != null) { plugins.add(new PackageAdminCommandGroup(context .getService(pkgAdminRef))); } shell = new Shell(System.out, System.err, (ShellCommandGroup[]) plugins .toArray(new ShellCommandGroup[plugins.size()])); context.addServiceListener(shell, "(" + Constants.OBJECTCLASS + "=" + ShellCommandGroup.class.getName() + ")"); final Collection<ServiceReference<ShellCommandGroup>> existingGroups = context .getServiceReferences(ShellCommandGroup.class, null); if (existingGroups != null) { for (final ServiceReference<ShellCommandGroup> group : existingGroups) { shell.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, group)); } } }
Example #24
Source File: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get default service reference from the target BC. * @return */ public static <T> T getTargetBC_getService(final ServiceReference<T> sr) { final BundleContext tbc = getTargetBC(); if(null != tbc) { return tbc.getService(sr); } return null; }
Example #25
Source File: LinkerBinderManager.java From fuchsia with Apache License 2.0 | 5 votes |
/** * Remove all the existing links of the DeclarationBinder. * * @param declarationBinderRef the ServiceReference<DeclarationBinder> of the DeclarationBinder */ public void removeLinks(ServiceReference<S> declarationBinderRef) { for (D declaration : linkerManagement.getMatchedDeclaration()) { if (declaration.getStatus().getServiceReferencesBounded().contains(declarationBinderRef)) { linkerManagement.unlink(declaration, declarationBinderRef); } } }
Example #26
Source File: JpaAuditListenerMetadataProvider.java From gvnix with GNU General Public License v3.0 | 5 votes |
public JpaAuditOperationsMetadata getOperations() { if (operations == null) { // Get all Services implement JpaAuditOperationsMetadata interface try { ServiceReference<?>[] references = this.context .getAllServiceReferences( JpaAuditOperationsMetadata.class.getName(), null); for (ServiceReference<?> ref : references) { return (JpaAuditOperationsMetadata) this.context .getService(ref); } return null; } catch (InvalidSyntaxException e) { LOGGER.warning("Cannot load JpaAuditOperationsMetadata on JpaAuditListenerMetadataProvider."); return null; } } else { return operations; } }
Example #27
Source File: FilterMenuOperationsHook.java From gvnix with GNU General Public License v3.0 | 5 votes |
/** * Filter request returned by framework related to {@link MenuOperations}. <br> * This method only manage the {@link MenuOperations} service request, * removing from returned collection {@code references} all services except * {@link MenuOperationsProxy}. <br> * For request inside this bundle all services are returned. * * @see org.osgi.framework.hooks.service.FindHook#find(org.osgi.framework.BundleContext, * java.lang.String, java.lang.String, boolean, java.util.Collection) */ public void find(BundleContext context, String name, String filter, boolean allServices, Collection references) { if (!MENU_OPERATION_NAME.equals(name)) { // It's not the managed service // Do nothing return; } if (context.getBundle().getBundleId() == 0) { // Don't hide anything from the system bundle return; } if (references.isEmpty()) { // Nothing to do return; } if (bundleContext.equals(context)) { // Don't hide anything to myself return; } // Remove all ServiceReferes except MenuOpertationProxy service for (Iterator iter = references.iterator(); iter.hasNext();) { ServiceReference sr = (ServiceReference) iter.next(); if (isGvNIXOperations(sr)) { // logger.finest(" - gvNIX Menu op ( Removing)"); iter.remove(); } else if (isProxy(sr)) { // Don't remove proxy continue; } else { // logger.finest(" - Roo Menu op ( Removing)"); iter.remove(); } } }
Example #28
Source File: ServiceHooks.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
synchronized void open() { if(fwCtx.debug.hooks) { fwCtx.debug.println("opening hooks"); } listenerHookTracker = new ServiceTracker<ListenerHook,ListenerHook> (fwCtx.systemBundle.bundleContext, ListenerHook.class, new ServiceTrackerCustomizer<ListenerHook,ListenerHook>() { public ListenerHook addingService(ServiceReference<ListenerHook> reference) { final ListenerHook lh = fwCtx.systemBundle.bundleContext.getService(reference); try { Collection<ServiceListenerEntry> c = getServiceCollection(); @SuppressWarnings({ "rawtypes", "unchecked" }) final Collection<ListenerInfo> li = (Collection) c; lh.added(li); } catch (final Exception e) { fwCtx.debug.printStackTrace("Failed to call listener hook #" + reference.getProperty(Constants.SERVICE_ID), e); } return lh; } public void modifiedService(ServiceReference<ListenerHook> reference, ListenerHook service) { // noop } public void removedService(ServiceReference<ListenerHook> reference, ListenerHook service) { fwCtx.systemBundle.bundleContext.ungetService(reference); } }); listenerHookTracker.open(); bOpen = true; }
Example #29
Source File: ComponentContextImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) ComponentServiceObjectsImpl<?> getComponentServiceObjects(ServiceReference<?> sr, ReferenceListener rl) { synchronized (cciBound) { ComponentServiceObjectsImpl<?> cso = cciBound.get(sr); if (cso == null) { cso = new ComponentServiceObjectsImpl(this, sr, rl); cciBound.put(sr, cso); } else { cso.addReferenceListener(rl); } return cso; } }
Example #30
Source File: ServiceTracker.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * {@code ServiceListener} method for the {@code ServiceTracker} class. * This method must NOT be synchronized to avoid deadlock potential. * * @param event {@code ServiceEvent} object from the framework. */ final public void serviceChanged(final ServiceEvent event) { /* * Check if we had a delayed call (which could happen when we * close). */ if (closed) { return; } @SuppressWarnings("unchecked") final ServiceReference<S> reference = (ServiceReference<S>) event.getServiceReference(); if (DEBUG) { System.out.println("ServiceTracker.Tracked.serviceChanged[" + event.getType() + "]: " + reference); } switch (event.getType()) { case ServiceEvent.REGISTERED : case ServiceEvent.MODIFIED : track(reference, event); /* * If the customizer throws an unchecked exception, it is * safe to let it propagate */ break; case ServiceEvent.MODIFIED_ENDMATCH : case ServiceEvent.UNREGISTERING : untrack(reference, event); /* * If the customizer throws an unchecked exception, it is * safe to let it propagate */ break; } }