org.osgi.framework.ServiceRegistration Java Examples
The following examples show how to use
org.osgi.framework.ServiceRegistration.
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: Examples.java From osgi.enroute.examples with Apache License 2.0 | 6 votes |
@Tooltip(description = "Register a service with a cron expression.", deflt = "30/2 * * * * ?", type = "text") public CancellablePromise<?> cronService(int id, String cronExpression, Callable<Void> callable) { // // If you use the generic version, don't use Lambdas CronJob<CronData> job = new CronJob<Examples.CronData>() { public void run(CronData cronData) throws Exception { out.println("Fired cron service " + id + cronData.message()); callable.call(); } }; @SuppressWarnings("rawtypes") ServiceRegistration<CronJob> registration = context.registerService( CronJob.class, job, new Hashtable<String, Object>() { private static final long serialVersionUID = 1L; { put(CronJob.CRON, cronExpression); } }); return new Closer<Object>(() -> registration.unregister()); }
Example #2
Source File: ProtobufferImporterTest.java From fuchsia with Apache License 2.0 | 6 votes |
public void initInterceptors() throws Exception { super.initInterceptors(); when(context.registerService(anyString(), anyObject(), any(Dictionary.class))).thenAnswer(new Answer<ServiceRegistration>() { public ServiceRegistration answer(InvocationOnMock invocationOnMock) throws Throwable { if (invocationOnMock.getArguments()[1] == null) { throw new NullPointerException("object to be registered is null"); } protobufferRemoteServiceProxy = (AddressBookProtos.AddressBookService) invocationOnMock.getArguments()[1]; return proxyServiceRegistration; } }); fuchsiaDeclarationBinder = spy(constructor().withParameterTypes(BundleContext.class).in(ProtobufferImporter.class).newInstance(context)); declaration = getValidDeclarations().get(0); declaration.bind(fuchsiaDeclarationBinderServiceReference); fuchsiaDeclarationBinder.registration(fuchsiaDeclarationBinderServiceReference); fuchsiaDeclarationBinder.start(); }
Example #3
Source File: HeosHandlerFactory.java From org.openhab.binding.heos with Eclipse Public License 1.0 | 6 votes |
@Override public void unregisterHandler(Thing thing) { if (thing.getThingTypeUID().equals(THING_TYPE_BRIDGE)) { super.unregisterHandler(thing); ServiceRegistration<?> serviceRegistration = this.discoveryServiceRegs.get(thing.getUID()); if (serviceRegistration != null) { serviceRegistration.unregister(); discoveryServiceRegs.remove(thing.getUID()); logger.info("Unregister discovery service for HEOS player and HEOS groups by bridge '{}'", thing.getUID().getId()); } } if (thing.getThingTypeUID().equals(THING_TYPE_PLAYER) || thing.getThingTypeUID().equals(THING_TYPE_GROUP)) { super.unregisterHandler(thing); ServiceRegistration<AudioSink> reg = audioSinkRegistrations.get(thing.getUID().toString()); if (reg != null) { reg.unregister(); } } }
Example #4
Source File: CatalogDataResourceProviderManagerImplTest.java From commerce-cif-connector with Apache License 2.0 | 6 votes |
@Before public void beforeTest() throws Exception { getRepository().getDefaultWorkspace(); session = getAdminSession(); session.getWorkspace().getNamespaceRegistry().registerNamespace("cq", "http://www.day.com/jcr/cq/1.0"); RepositoryUtil.registerSlingNodeTypes(session); manager = new CatalogDataResourceProviderManagerImpl(); PrivateAccessor.setField(manager, "resolverFactory", getResourceResolverFactory()); BundleContext bundleContext = Mockito.mock(BundleContext.class); Mockito.when(bundleContext.registerService((Class) Mockito.any(), (ResourceProvider) Mockito.any(), Mockito.any())).thenAnswer( (Answer<ServiceRegistration>) invocation -> Mockito.mock(ServiceRegistration.class)); componentContext = Mockito.mock(ComponentContext.class); Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext); }
Example #5
Source File: Utils.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
public static void updateProperty( ServiceRegistration<?> serviceRegistration, String key, Object value) { CachingServiceReference<?> serviceReference = new CachingServiceReference<>(serviceRegistration.getReference()); Dictionary<String, Object> properties = new Hashtable<>(); for (String propertyKey : serviceReference.getPropertyKeys()) { properties.put( propertyKey, serviceReference.getProperty(propertyKey)); } properties.put(key, value); serviceRegistration.setProperties(properties); }
Example #6
Source File: DefaultSwingBundleDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public ServiceRegistration<SwingBundleDisplayer> register() { if (reg != null) { return reg; } open(); final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(SwingBundleDisplayer.PROP_NAME, getName()); props.put(SwingBundleDisplayer.PROP_DESCRIPTION, getDescription()); props.put(SwingBundleDisplayer.PROP_ISDETAIL, isDetail() ? Boolean.TRUE : Boolean.FALSE); // Register this displayer service in the local framework. reg = Activator.bc.registerService(SwingBundleDisplayer.class, this, props); return reg; }
Example #7
Source File: ApplicationConfigurationImpl.java From wisdom with Apache License 2.0 | 6 votes |
private void registerFirstLevelConfigurationAsServices() { // Registers configuration if (appConf == null) { return; } for (Map.Entry<String, ConfigValue> entry : appConf.root().entrySet()) { if (entry.getValue().valueType() == ConfigValueType.OBJECT) { // Register it. Dictionary<String, String> properties = new Hashtable<>(); properties.put("configuration.name", entry.getKey()); properties.put("configuration.path", entry.getKey()); final ConfigurationImpl cf = new ConfigurationImpl(converters, appConf.getConfig(entry.getKey())); ServiceRegistration<Configuration> reg = context.registerService(Configuration.class, cf, properties); confRegistrations.put(cf, reg); } } }
Example #8
Source File: TestHelper.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
protected ServiceRegistration<?> registerInvalidExtension( String name, Object... keyValues) { TestFilter testFilter = new TestFilter(); Hashtable<String, Object> properties = new Hashtable<>(); properties.put(JAX_RS_EXTENSION, true); properties.put(JAX_RS_NAME, name); properties.putIfAbsent( JAX_RS_APPLICATION_SELECT, "(osgi.jaxrs.name=*)"); for (int i = 0; i < keyValues.length; i = i + 2) { properties.put(keyValues[i].toString(), keyValues[i + 1]); } ServiceRegistration<Object> serviceRegistration = bundleContext.registerService( Object.class, testFilter, properties); _registrations.add(serviceRegistration); return serviceRegistration; }
Example #9
Source File: JmxWrapperForMessagingClientTest.java From roboconf-platform with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings( "unchecked" ) public void testConstructor_mockOsgi() { ServiceRegistration<MessagingApiMBean> serviceReg = Mockito.mock( ServiceRegistration.class ); BundleContext bundleCtx = Mockito.mock( BundleContext.class ); Mockito.when( bundleCtx.registerService( Mockito.eq( MessagingApiMBean.class ), Mockito.any( JmxWrapperForMessagingClient.class ), Mockito.any( Dictionary.class ))).thenReturn( serviceReg ); OsgiHelper osgiHelper = Mockito.mock( OsgiHelper.class ); Mockito.when( osgiHelper.findBundleContext()).thenReturn( bundleCtx ); IMessagingClient messagingClient = Mockito.mock( IMessagingClient.class ); JmxWrapperForMessagingClient client = new JmxWrapperForMessagingClient( messagingClient, osgiHelper ); Assert.assertNotNull( client.serviceReg ); Assert.assertEquals( serviceReg, client.serviceReg ); }
Example #10
Source File: DeclarationRegistrationManager.java From fuchsia with Apache License 2.0 | 6 votes |
/** * Utility method to register an Declaration has a Service in OSGi. * If you use it make sure to use unregisterDeclaration(...) to unregister the Declaration * * @param declaration the Declaration to register */ public void registerDeclaration(T declaration) { synchronized (declarationsRegistered) { if (declarationsRegistered.containsKey(declaration)) { throw new IllegalStateException("The given Declaration has already been registered."); } Dictionary<String, Object> props = new Hashtable<String, Object>(); if(declaration.getMetadata().get("id") != null){ props.put("importer.id",declaration.getMetadata().get("id").toString()); } String[] clazzes = new String[]{klass.getName()}; ServiceRegistration registration; registration = bundleContext.registerService(clazzes, declaration, props); declarationsRegistered.put(declaration, registration); } }
Example #11
Source File: ThymeleafTemplateCollector.java From wisdom with Apache License 2.0 | 6 votes |
/** * Deletes the given template. The service is unregistered, and the cache is cleared. * * @param template the template */ public void deleteTemplate(ThymeLeafTemplateImplementation template) { // 1 - unregister the service try { ServiceRegistration reg = registrations.remove(template); if (reg != null) { reg.unregister(); } } catch (Exception e) { //NOSONAR // May already have been unregistered during the shutdown sequence. } // 2 - as templates can have dependencies, and expressions kept in memory, we clear all caches. // Despite this may really impact performance, it should not happen too often on real systems. synchronized (this) { engine.getCacheManager().clearAllCaches(); } OgnlRuntime.clearCache(); // Unfortunately, the previous method do not clear the get and set method cache // (ognl.OgnlRuntime.cacheGetMethod and ognl.OgnlRuntime.cacheSetMethod) clearMethodCaches(); }
Example #12
Source File: BeanConfigurationFactory.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@Override protected Entry<BeanServiceInstance> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { final BeanServiceInstance bean = new BeanServiceInstance ( this.beanClazz.newInstance () ); if ( this.mergeIdField ) { parameters.put ( "id", configurationId ); } bean.update ( parameters ); final ServiceRegistration<?> reg = context.registerService ( this.beanClazz.getName (), bean.getTargetBean (), bean.getProperties () ); return new Entry<BeanServiceInstance> ( configurationId, bean, reg ); }
Example #13
Source File: AbstractServiceFactory.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@Override public synchronized void delete ( final UserInformation information, final String configurationId ) throws Exception { final ServiceRegistration<?> reg = this.regs.remove ( configurationId ); if ( reg != null ) { reg.unregister (); } final Service service = this.instances.remove ( configurationId ); if ( service != null ) { service.dispose (); } }
Example #14
Source File: DefaultSwingBundleDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public ServiceRegistration<SwingBundleDisplayer> register() { if (reg != null) { return reg; } open(); final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(SwingBundleDisplayer.PROP_NAME, getName()); props.put(SwingBundleDisplayer.PROP_DESCRIPTION, getDescription()); props.put(SwingBundleDisplayer.PROP_ISDETAIL, isDetail() ? Boolean.TRUE : Boolean.FALSE); reg = Activator.getBC() .registerService(SwingBundleDisplayer.class, this, props); return reg; }
Example #15
Source File: AbstractDiscoveryComponentTest.java From fuchsia with Apache License 2.0 | 6 votes |
@Test public void testUnregisterImportDeclaration() { TestedClass testedClass = new TestedClass(bundleContext); testedClass.start(); Map<String, Object> md = new HashMap<String, Object>(); md.put("md", "value"); ImportDeclaration id = ImportDeclarationBuilder.fromMetadata(md).build(); ServiceRegistration mockSR = mock(ServiceRegistration.class); testedClass.addIdec(id); testedClass.removeIdec(id); assertThat(testedClass.getImportDeclarations()).isEmpty(); }
Example #16
Source File: JaxrsTest.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
@Test public void testErroredExtension() { registerApplication(new TestApplication()); ServiceRegistration<Feature> serviceRegistration = registerExtension( Feature.class, context -> { throw new RuntimeException(); }, "ErrorFeature", JAX_RS_APPLICATION_SELECT, "(" + JAX_RS_APPLICATION_BASE + "=/test-application)"); RuntimeDTO runtimeDTO = _runtime.getRuntimeDTO(); assertEquals(1, runtimeDTO.failedExtensionDTOs.length); assertEquals( serviceRegistration.getReference().getProperty("service.id"), runtimeDTO.failedExtensionDTOs[0].serviceId); assertEquals( DTOConstants.FAILURE_REASON_UNKNOWN, runtimeDTO.failedExtensionDTOs[0].failureReason); }
Example #17
Source File: ProxyEventQueryFactory.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@Override protected Entry<ProxyEventQuery> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { logger.info ( "Creating new proxy query: {}", configurationId ); final ConfigurationDataHelper cfg = new ConfigurationDataHelper ( parameters ); final int poolSize = cfg.getIntegerChecked ( "poolSize", "'poolSize' must be set" ); if ( poolSize <= 0 ) { throw new IllegalArgumentException ( "'poolSize' must be a positive integer greater zero" ); } final ProxyEventQuery service = new ProxyEventQuery ( context, this.executor, poolSize, parameters ); final Hashtable<String, Object> properties = new Hashtable<String, Object> (); properties.put ( Constants.SERVICE_PID, configurationId ); final ServiceRegistration<EventQuery> handle = context.registerService ( EventQuery.class, service, properties ); return new Entry<ProxyEventQuery> ( configurationId, service, handle ); }
Example #18
Source File: ConnectorRegistrarImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override public void addConnector(final ConnectorConfiguration connectorConfiguration) { checkNotNull(connectorConfiguration); validate(connectorConfiguration); final Bundle bundle = FrameworkUtil.getBundle(connectorConfiguration.getClass()); if (bundle == null) { log.warn("No bundle found for {}, not registering connector", connectorConfiguration); return; } final BundleContext bundleContext = bundle.getBundleContext(); if (bundleContext == null) { log.warn("No context found for bundle {}, not registering connector", bundle); return; } log.info("Adding connector configuration {}", connectorConfiguration); final ServiceRegistration<ConnectorConfiguration> serviceRegistration = bundleContext.registerService(ConnectorConfiguration.class, connectorConfiguration, null); managedConfigurations.put(connectorConfiguration, serviceRegistration); }
Example #19
Source File: VertxSingleton.java From wisdom with Apache License 2.0 | 5 votes |
private static void unregisterQuietly(ServiceRegistration reg) { if (reg != null) { try { reg.unregister(); } catch (IllegalStateException e) { // Ignore it. } } }
Example #20
Source File: BaseThingHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void registerFirmwareUpdateHandler(Thing thing, ThingHandler thingHandler) { if (thingHandler instanceof FirmwareUpdateHandler) { ServiceRegistration<FirmwareUpdateHandler> serviceRegistration = registerAsService(thingHandler, FirmwareUpdateHandler.class); firmwareUpdateHandlers.put(thing.getUID().getAsString(), serviceRegistration); } }
Example #21
Source File: DefaultImportationLinkerTest.java From fuchsia with Apache License 2.0 | 5 votes |
/** * Test that ImporterServices are binded when filter match. */ @Test public void testBindImporterServices() { assertThat(importationLinkerIntrospection.getLinkedImporters()).isEmpty(); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(INSTANCE_NAME_PROPERTY, "importer1-instance"); props.put(DeclarationBinder.TARGET_FILTER_PROPERTY, "(" + Constants.ID + "=test)"); ServiceRegistration<ImporterService> sr1 = context.registerService(ImporterService.class, importer1, props); ImporterService is = osgiHelper.waitForService(ImporterService.class, "(" + INSTANCE_NAME_PROPERTY + "=importer1-instance)", 0); assertThat(is).isNotNull(); assertThat(importationLinkerIntrospection.getLinkedImporters()).containsOnly(importer1); Dictionary<String, Object> props2 = new Hashtable<String, Object>(); props2.put(INSTANCE_NAME_PROPERTY, "importer2-instance"); props2.put(DeclarationBinder.TARGET_FILTER_PROPERTY, "(" + Constants.ID + "=test)"); ServiceRegistration<ImporterService> sr2 = context.registerService(ImporterService.class, importer2, props2); ImporterService is2 = osgiHelper.waitForService(ImporterService.class, "(" + INSTANCE_NAME_PROPERTY + "=importer2-instance)", 0); assertThat(is2).isNotNull(); assertThat(importationLinkerIntrospection.getLinkedImporters()).containsOnly(importer1, importer2); sr1.unregister(); assertThat(importationLinkerIntrospection.getLinkedImporters()).containsOnly(importer2); sr2.unregister(); assertThat(importationLinkerIntrospection.getLinkedImporters()).isEmpty(); }
Example #22
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 msOffice2Xliff = new MSOffice2Xliff(); Properties properties = new Properties(); properties.put(Converter.ATTR_NAME, MSOffice2Xliff.NAME_VALUE); properties.put(Converter.ATTR_TYPE, MSOffice2Xliff.TYPE_VALUE); properties.put(Converter.ATTR_TYPE_NAME, MSOffice2Xliff.TYPE_NAME_VALUE); ServiceRegistration registration = ConverterRegister.registerPositiveConverter(bundleContext, msOffice2Xliff, properties); return registration; }
Example #23
Source File: ExporterDeclarationInstance.java From fuchsia with Apache License 2.0 | 5 votes |
private void importDeclaration() { Map<String, Object> metadata = new HashMap<String, Object>(); metadata.put(ID, "endipoint"); metadata.put(URL, "http://localhost:8080/JSONRPC/DummyPojoInstance"); metadata.put(SERVICE_CLASS, "org.ow2.chameleon.fuchsia.examples.jsonrpc.exporter.experiment.DummyIface"); metadata.put(CONFIGS, "jsonrpc"); ImportDeclaration declaration = ImportDeclarationBuilder.fromMetadata(metadata).build(); String clazzes[] = new String[]{ImportDeclaration.class.getName()}; Dictionary<String, Object> props = new Hashtable<String, Object>(); ServiceRegistration registration = context.registerService(clazzes, declaration, props); }
Example #24
Source File: PhilipsHueImporter.java From fuchsia with Apache License 2.0 | 5 votes |
private void cleanup() { for (Map.Entry<String, ServiceRegistration> lampEntry : lamps.entrySet()) { lamps.remove(lampEntry.getKey()).unregister(); } for (Map.Entry<String, ServiceRegistration> bridgeEntry : bridges.entrySet()) { bridges.remove(bridgeEntry.getKey()).unregister(); } }
Example #25
Source File: OSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Register the given object as OSGi service. * * <p> * The given interface names are used as OSGi service interface name. * * @param service service to be registered * @param interfaceName interface name of the OSGi service * @param properties OSGi service properties * @return service registration object */ protected ServiceRegistration<?> registerService(final Object service, final String[] interfaceNames, final Dictionary<String, ?> properties) { assertThat(interfaceNames, is(notNullValue())); final ServiceRegistration<?> srvReg = bundleContext.registerService(interfaceNames, service, properties); for (final String interfaceName : interfaceNames) { saveServiceRegistration(interfaceName, srvReg); } return srvReg; }
Example #26
Source File: ManagedProcessEngineFactoryImpl.java From camunda-bpm-platform-osgi with Apache License 2.0 | 5 votes |
@Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (existingEngines.containsKey(pid)) { existingEngines.get(pid).close(); existingEngines.remove(pid); existingRegisteredEngines.get(pid).unregister(); existingRegisteredEngines.remove(pid); } if (!hasPropertiesConfiguration(properties)) { return; } ClassLoader previous = Thread.currentThread().getContextClassLoader(); ProcessEngine engine; try { ClassLoader cl = new BundleDelegatingClassLoader(bundle); Thread.currentThread().setContextClassLoader( new ClassLoaderWrapper(cl, ProcessEngineFactory.class.getClassLoader(), ProcessEngineConfiguration.class.getClassLoader(), previous)); ProcessEngineConfiguration processEngineConfiguration = createProcessEngineConfiguration(properties); processEngineConfiguration.setClassLoader(cl); engine = processEngineConfiguration.buildProcessEngine(); } finally { Thread.currentThread().setContextClassLoader(previous); } existingEngines.put(pid, engine); Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put("process-engine-name", engine.getName()); ServiceRegistration<ProcessEngine> serviceRegistration = this.bundle.getBundleContext().registerService(ProcessEngine.class, engine, props); existingRegisteredEngines.put(pid, serviceRegistration); }
Example #27
Source File: ConsoleSupportRfc147.java From smarthome with Eclipse Public License 2.0 | 5 votes |
public void removeConsoleCommandExtension(ConsoleCommandExtension consoleCommandExtension) { final ServiceRegistration<?> old; old = commands.remove(consoleCommandExtension); if (old != null) { unregisterCommand(old); } }
Example #28
Source File: ActivatorSL4.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void start(BundleContext context) throws Exception { final ServiceRegistration registration = context.registerService(FooService.class.getName(), this, null); System.out.println("bundleSL4: Registered " + registration); }
Example #29
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 inx2Xliff = new OpenOffice2Xliff(converter); Properties properties = new Properties(); properties.put(Converter.ATTR_NAME, OpenOffice2Xliff.NAME_VALUE); properties.put(Converter.ATTR_TYPE, OpenOffice2Xliff.TYPE_VALUE); properties.put(Converter.ATTR_TYPE_NAME, OpenOffice2Xliff.TYPE_NAME_VALUE); ServiceRegistration registration = ConverterRegister.registerPositiveConverter(bundleContext, inx2Xliff, properties); return registration; }
Example #30
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 inx2Xliff = new MSOffice2Xliff(converter); Properties properties = new Properties(); properties.put(Converter.ATTR_NAME, MSOffice2Xliff.NAME_VALUE); properties.put(Converter.ATTR_TYPE, MSOffice2Xliff.TYPE_VALUE); properties.put(Converter.ATTR_TYPE_NAME, MSOffice2Xliff.TYPE_NAME_VALUE); ServiceRegistration registration = ConverterRegister.registerPositiveConverter(bundleContext, inx2Xliff, properties); return registration; }