org.osgi.service.cm.ManagedServiceFactory Java Examples
The following examples show how to use
org.osgi.service.cm.ManagedServiceFactory.
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: Update.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void doUpdate(PluginManager pm) throws ConfigurationException { if (sr == null) { return; } Object targetService = getTargetService(); if (targetService == null) { return; } processedConfiguration = pm.callPluginsAndCreateACopy(sr, configuration); if (factoryPid == null) { update((ManagedService) targetService); } else { update((ManagedServiceFactory) targetService); } }
Example #2
Source File: HTTPUndertowTransportActivator.java From cxf with Apache License 2.0 | 6 votes |
public void start(BundleContext ctx) throws Exception { this.context = ctx; reg = context.registerService(ManagedServiceFactory.class.getName(), this, CollectionUtils.singletonDictionary(Constants.SERVICE_PID, FACTORY_PID)); mbeanServerTracker = new ServiceTracker<>(ctx, MBeanServer.class, null); try { BlueprintNameSpaceHandlerFactory nsHandlerFactory = new BlueprintNameSpaceHandlerFactory() { @Override public Object createNamespaceHandler() { return new HTTPUndertowTransportNamespaceHandler(); } }; NamespaceHandlerRegisterer.register(context, nsHandlerFactory, "http://cxf.apache.org/transports/http-undertow/configuration"); } catch (NoClassDefFoundError e) { // Blueprint not available, ignore } }
Example #3
Source File: HTTPJettyTransportActivator.java From cxf with Apache License 2.0 | 6 votes |
public void start(BundleContext ctx) throws Exception { this.context = ctx; reg = context.registerService(ManagedServiceFactory.class, this, CollectionUtils.singletonDictionary(Constants.SERVICE_PID, FACTORY_PID)); mbeanServerTracker = new ServiceTracker<>(ctx, MBeanServer.class, null); try { BlueprintNameSpaceHandlerFactory nsHandlerFactory = new BlueprintNameSpaceHandlerFactory() { @Override public Object createNamespaceHandler() { return new HTTPJettyTransportNamespaceHandler(); } }; NamespaceHandlerRegisterer.register(context, nsHandlerFactory, "http://cxf.apache.org/transports/http-jetty/configuration"); } catch (NoClassDefFoundError e) { // Blueprint not available, ignore } }
Example #4
Source File: Config.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
void start(BundleContext bc) { this.bc = bc; final Dictionary<String, String> props = new Hashtable<String, String>(); props.put(PID, msfPid); if (dying) { return; } sreg = bc.registerService(ManagedServiceFactory.class, this, props); synchronized (this) { if (!dying) { return; } } stop(); }
Example #5
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void serviceChanged(ServiceReference<?> sr, int eventType, String objectClass) { if (ManagedServiceFactory.class.getName().equals(objectClass)) { @SuppressWarnings("unchecked") final ServiceReference<ManagedServiceFactory> srF = (ServiceReference<ManagedServiceFactory>) sr; managedServiceFactoryChanged(srF, eventType); } else if (ManagedService.class.getName().equals(objectClass)) { @SuppressWarnings("unchecked") final ServiceReference<ManagedService> srM = (ServiceReference<ManagedService>) sr; managedServiceChanged(srM, eventType); } else if (ConfigurationPlugin.class.getName().equals(objectClass)) { @SuppressWarnings("unchecked") final ServiceReference<ConfigurationPlugin> srC = (ServiceReference<ConfigurationPlugin>) sr; pluginManager.configurationPluginChanged(srC, eventType); } }
Example #6
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
void updateManagedServiceFactories(Collection<ServiceReference<ManagedServiceFactory>> srs, String servicePid, String factoryPid, String boundLocation) { final Collection<ServiceReference<ManagedServiceFactory>> filtered = filterOnMatchingLocations(srs, boundLocation); for (final ServiceReference<ManagedServiceFactory> sr : filtered) { configurationDispatcher.dispatchUpdateFor(sr, servicePid, factoryPid, null); } }
Example #7
Source File: Activator.java From camunda-bpm-platform-osgi with Apache License 2.0 | 5 votes |
@Override public void init(BundleContext context, DependencyManager manager) throws Exception { manager.add(createComponent() .setInterface(ManagedServiceFactory.class.getName(), new Hashtable<String, String>(Collections.singletonMap(Constants.SERVICE_PID, ManagedProcessEngineFactory.SERVICE_PID))) .setImplementation(ManagedProcessEngineFactoryImpl.class).add(createBundleDependency().setBundle(context.getBundle()).setRequired(true))); }
Example #8
Source File: XOUnitBundleListener.java From extended-objects with Apache License 2.0 | 5 votes |
@Override public void start(BundleContext context) { context.addBundleListener(this); @SuppressWarnings("squid:S1149") Dictionary<String, String> props = new Hashtable<>(); props.put(Constants.SERVICE_PID, FACTORY_PID); serviceFactory = new XOManagerFactoryServiceFactory(context); serviceFactoryRegistration = context.registerService(ManagedServiceFactory.class, serviceFactory, props); if (LOGGER.isDebugEnabled()) { LOGGER.debug("ConfigAdmin listener registered"); } }
Example #9
Source File: CXFActivator.java From cxf with Apache License 2.0 | 5 votes |
/** {@inheritDoc}*/ public void start(BundleContext context) throws Exception { workQueues = new ManagedWorkQueueList(); cxfBundleListener = new CXFExtensionBundleListener(context.getBundle().getBundleId()); context.addBundleListener(cxfBundleListener); cxfBundleListener.registerExistingBundles(context); configAdminTracker = new ServiceTracker<>(context, ConfigurationAdmin.class, null); configAdminTracker.open(); workQueues.setConfigAdminTracker(configAdminTracker); workQueueServiceRegistration = registerManagedServiceFactory(context, ManagedServiceFactory.class, workQueues, ManagedWorkQueueList.FACTORY_PID); extensions = new ArrayList<>(); extensions.add(createOsgiBusListenerExtension(context)); extensions.add(createManagedWorkQueueListExtension(workQueues)); ExtensionRegistry.addExtensions(extensions); BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() { @Override public Object createNamespaceHandler() { return new CXFAPINamespaceHandler(); } }; NamespaceHandlerRegisterer.register(context, factory, "http://cxf.apache.org/blueprint/core", "http://cxf.apache.org/configuration/beans", "http://cxf.apache.org/configuration/parameterized-types", "http://cxf.apache.org/configuration/security", "http://schemas.xmlsoap.org/wsdl/", "http://www.w3.org/2005/08/addressing", "http://schemas.xmlsoap.org/ws/2004/08/addressing"); }
Example #10
Source File: HTTPTransportActivator.java From cxf with Apache License 2.0 | 5 votes |
public void start(final BundleContext context) throws Exception { ConfigAdminHttpConduitConfigurer conduitConfigurer = new ConfigAdminHttpConduitConfigurer(); registerService(context, ManagedServiceFactory.class, conduitConfigurer, ConfigAdminHttpConduitConfigurer.FACTORY_PID); registerService(context, HTTPConduitConfigurer.class, conduitConfigurer, "org.apache.cxf.http.conduit-configurer"); if (PropertyUtils.isTrue(context.getProperty(DISABLE_DEFAULT_HTTP_TRANSPORT))) { //TODO: Review if it also makes sense to support "http.transport.disable" // directly in the CXF_CONFIG_SCOPE properties file return; } DestinationRegistry destinationRegistry = new DestinationRegistryImpl(); HTTPTransportFactory transportFactory = new HTTPTransportFactory(destinationRegistry); HttpServiceTrackerCust customizer = new HttpServiceTrackerCust(destinationRegistry, context); httpServiceTracker = new ServiceTracker<>(context, HttpService.class, customizer); httpServiceTracker.open(); context.registerService(DestinationRegistry.class.getName(), destinationRegistry, null); context.registerService(HTTPTransportFactory.class.getName(), transportFactory, null); BlueprintNameSpaceHandlerFactory factory = new BlueprintNameSpaceHandlerFactory() { @Override public Object createNamespaceHandler() { return new HttpBPHandler(); } }; NamespaceHandlerRegisterer.register(context, factory, "http://cxf.apache.org/transports/http/configuration"); }
Example #11
Source File: FileInventoryServiceFactory.java From camelinaction2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void init() { Dictionary properties = new Properties(); properties.put( Constants.SERVICE_PID, "camelinaction.fileinventoryroutefactory"); registration = bundleContext.registerService(ManagedServiceFactory.class.getName(), this, properties); LOG.info("FileInventoryRouteCamelServiceFactory ready to accept " + "new config with PID=camelinaction.fileinventoryroutefactory-xxx"); }
Example #12
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateManagedServiceFactory(ServiceReference<ManagedServiceFactory> sr) throws IOException { // Newly registered managed service factory; all PIDs are added. final ChangedPids cps = new ChangedPids(); cps.added.addAll(Arrays.asList(getPids(sr))); updateManagedServiceFactory(sr, cps); }
Example #13
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
void updateManagedServiceFactories(ServiceReference<ManagedServiceFactory> sr, String servicePid, String factoryPid, ConfigurationDictionary cd) throws IOException { final ConfigurationDictionary bound = bindLocationIfNecessary(sr, cd); final String boundLocation = bound.getLocation(); if (locationsMatch(sr.getBundle(), boundLocation)) { configurationDispatcher.dispatchUpdateFor(sr, servicePid, factoryPid, bound); } }
Example #14
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public ConfigurationAdminFactory(File storeDir) { storeDir.mkdirs(); try { this.store = new ConfigurationStore(storeDir); } catch (final Exception e) { Activator.log.error("Error while initializing configurations store", e); } pluginManager = new PluginManager(); listenerEventQueue = new ListenerEventQueue(Activator.bc); configurationDispatcher = new ConfigurationDispatcher(pluginManager); lookForExisitingBundleLocations(); final String filter = "(|(objectClass=" + ManagedServiceFactory.class.getName() + ")" + "(objectClass=" + ManagedService.class.getName() + ")" + "(objectClass=" + ConfigurationPlugin.class.getName() + "))"; try { Activator.bc.addServiceListener(this, filter); Activator.bc.addBundleListener(this); } catch (final InvalidSyntaxException ignored) { } lookForAlreadyRegisteredServices(); }
Example #15
Source File: Update.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void update(ManagedServiceFactory targetService) throws ConfigurationException { if (targetService == null) { return; } if (processedConfiguration == null) { targetService.deleted(pid); } else { targetService.updated(pid, processedConfiguration); } }
Example #16
Source File: BundleMetaTypeInformationSnapshot.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void extractMetaTypeInformation(ServiceReference<?> sr) { Object s = null; try { s = bc.getService(sr); if (!(s instanceof MetaTypeProvider)) { return; } final MetaTypeProvider mtp = (MetaTypeProvider) s; final List<String> pidProps = new ArrayList<String>(); final List<String> fpidProps = new ArrayList<String>(); if(s instanceof ManagedService){ pidProps.add(Constants.SERVICE_PID); pidProps.add(MetaTypeProvider.METATYPE_PID); fpidProps.add(MetaTypeProvider.METATYPE_FACTORY_PID); } else if (s instanceof ManagedServiceFactory) { pidProps.add(MetaTypeProvider.METATYPE_PID); fpidProps.add(Constants.SERVICE_PID); fpidProps.add(MetaTypeProvider.METATYPE_FACTORY_PID); } else { // MetaTypeProvide service pidProps.add(MetaTypeProvider.METATYPE_PID); fpidProps.add(MetaTypeProvider.METATYPE_FACTORY_PID); } addSrPropertiesToListAndMapIds(sr, pidProps, pids, mtp); addSrPropertiesToListAndMapIds(sr, fpidProps, factoryPids, mtp); final String[] ls = mtp.getLocales(); if (ls != null && ls.length > 0) { locales.addAll(Arrays.asList(ls)); } } finally { if (s != null) { bc.ungetService(sr); } } }
Example #17
Source File: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void start(final BundleContext bc) throws Exception { this.bc = bc; factory = new FactoryImpl(bc); final String commaSeparatedUrls = bc.getProperty(REPOSITORY_XML_URLS); if(commaSeparatedUrls != null && !"".equals(commaSeparatedUrls)) { final StringTokenizer urls = new StringTokenizer(commaSeparatedUrls, ","); while(urls.hasMoreTokens()) { final String url = urls.nextToken().trim(); new Thread(new Runnable() { @Override public void run() { try { factory.create(url, null, null); } catch (final Exception e) { // TODO: Add logging } }}).run(); } } sr = bc.registerService(XmlBackedRepositoryFactory.class, factory, null); final Hashtable<String, String> h = new Hashtable<String, String>(); h.put(Constants.SERVICE_PID, REPOSITORY_XML_PID); msfr = bc.registerService(ManagedServiceFactory.class, new MSF(), h); if ("true".equals(bc.getProperty("org.knopflerfish.repository.ct.prime"))) { tckTracker = new ServiceTracker<String, String>(bc, String.class, new ServiceTrackerCustomizer<String, String>() { @Override public String addingService(ServiceReference<String> reference) { if (reference.getProperty("repository-xml") == null) { return null; } final String xml = bc.getService(reference); new Thread(new Runnable() { @Override public void run() { Dictionary<String, String> p = new Hashtable<String, String>(); p.put("repository-populated", "org.osgi.test.cases.repository.junit.RepositoryTest"); try { factory.createFromString(xml); } catch (final Exception e) { // TODO: Add logging } bc.registerService(Object.class, new Object(), p); } }).run(); return xml; } @Override public void modifiedService(ServiceReference<String> r, String s) { } @Override public void removedService(ServiceReference<String> r, String s) { } }); tckTracker.open(); } }
Example #18
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void updateManagedServiceFactoriesMatching(String servicePid, String targetedFactoryPid, String oldBundleLocation) throws IOException { String factoryPid = targetedFactoryPid; Collection<ServiceReference<ManagedServiceFactory>> srs = getServiceReferencesWithPid(ManagedServiceFactory.class, factoryPid); if (srs.isEmpty()) { // No MSF with PID factoryPid, check it the given targeted factory PID // specifies a target. final int barPos = targetedFactoryPid.indexOf('|'); if (barPos > 0) { factoryPid = targetedFactoryPid.substring(0, barPos); srs = getServiceReferencesWithPid(ManagedServiceFactory.class, factoryPid); // Here we can filter {@code srs} on the target specification since we // do not need to replace a bound configuration with another more / less // specific one based on the matching rules for targeted PIDs. srs = filterOnTargetedPid(srs, targetedFactoryPid); } } if (srs.isEmpty()) { // No managed service factories matching this factory PID. return; } final ConfigurationDictionary cd = load(servicePid, null); if (cd == null) { // Deleted configuration instance, tell the MSFs. updateManagedServiceFactories(srs, servicePid, factoryPid, oldBundleLocation); } else { // New or updated factory configuration instance final ServiceReference<ManagedServiceFactory> bestSr = srs.iterator().next(); final ConfigurationDictionary bound = bindLocationIfNecessary(bestSr, cd); final String newBundleLocation = bound.getLocation(); final Collection<ServiceReference<ManagedServiceFactory>> filtered = filterOnMatchingLocations(srs, newBundleLocation); for (final ServiceReference<ManagedServiceFactory> sr : filtered) { if (targetedPidMatches(targetedFactoryPid, sr.getBundle())) { // This factory configuration instance is targeted at the bundle that // has registered the MSF configurationDispatcher.dispatchUpdateFor(sr, servicePid, factoryPid, bound); } } } }
Example #19
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void lookForAlreadyRegisteredServices() { lookForAlreadyRegisteredServices(ConfigurationPlugin.class); lookForAlreadyRegisteredServices(ManagedServiceFactory.class); lookForAlreadyRegisteredServices(ManagedService.class); }
Example #20
Source File: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void start(BundleContext bc) throws Exception { m_bc = bc; m_log = new LogRef(m_bc); m_factory = new SslServiceFactory(m_bc, m_log); final Dictionary<String, Object> parameters = new Hashtable<String, Object>(); parameters.put("service.pid", SslServiceFactory.PID); m_reg = bc.registerService(ManagedServiceFactory.class, m_factory, parameters); ServiceReference<ConfigurationAdmin> adminRef = null; try { ConfigurationAdmin admin = null; Configuration[] configs = null; try { adminRef = bc.getServiceReference(ConfigurationAdmin.class); // Potential start order problem! if (adminRef != null) { admin = bc.getService(adminRef); final String filter = "(&(service.m_factoryPid=" + SslServiceFactory.PID + ")" + "(|(service.bundleLocation=" + bc.getBundle().getLocation() + ")" + "(service.bundleLocation=NULL)" + "(!(service.bundleLocation=*))))"; configs = admin.listConfigurations(filter); } } catch (final Exception e) { if (m_log.doDebug()) { m_log.debug("Exception when trying to get CM", e); } } if (admin == null) { if (m_log.doInfo()) { m_log.info("No CM present, using default configuration"); } m_factory.updated(SslServiceWrapper.DEFAULT_SERVICE_PID, SslServiceWrapper.getDefaultConfig()); } else { if (configs == null || configs.length == 0) { if (m_log.doInfo()) { m_log .info("No configuration present, creating default configuration"); } m_factory.updated(SslServiceFactory.PID, SslServiceWrapper.getDefaultConfig()); } } } catch (final ConfigurationException ce) { m_log.error("Configuration error", ce); } finally { if (adminRef != null) { m_bc.ungetService(adminRef); } } }
Example #21
Source File: Activator.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void start(BundleContext bc) { Activator.bc = bc; log = new LogRef(bc, true); serverFactory = new HttpServerFactory(bc, log); final Dictionary<String, String> parameters = new Hashtable<String, String>(); parameters.put("service.pid", FACTORY_PID); configReg = bc.registerService(ManagedServiceFactory.class, serverFactory, parameters); ServiceReference<ConfigurationAdmin> adminRef = null; try { ConfigurationAdmin admin = null; Configuration[] configs = null; try { adminRef = bc.getServiceReference(ConfigurationAdmin.class); // Potential start order problem! if (adminRef != null) { admin = bc.getService(adminRef); final String filter = "(&(service.factoryPid=" + FACTORY_PID + ")" + "(|(service.bundleLocation=" + bc.getBundle().getLocation() + ")" + "(service.bundleLocation=NULL)" + "(!(service.bundleLocation=*))))"; configs = admin.listConfigurations(filter); } } catch (final Exception e) { if (log.doDebug()) { log.debug("Exception when trying to get CM", e); } } if (admin == null) { if (log.doInfo()) { log.info("No CM present, using default configuration"); } serverFactory.updated(HttpServerFactory.DEFAULT_PID, HttpConfig.getDefaultConfig(bc)); } else { if (configs == null || configs.length == 0) { if (log.doInfo()) { log.info("No configuration present, creating default configuration"); } serverFactory.updated(HttpServerFactory.DEFAULT_PID, HttpConfig.getDefaultConfig(bc)); } } } catch (final ConfigurationException ce) { if (log.doError()) { log.error("Configuration error", ce); } } finally { if (adminRef != null) { bc.ungetService(adminRef); } } registerCommandGroup(); }