org.osgi.service.cm.ManagedService Java Examples
The following examples show how to use
org.osgi.service.cm.ManagedService.
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: GPIOActivator.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Called when this bundle is started by OSGi Framework. * Determines underlying platform and loads the relevant service * which implements <code>GPIO</code> interface. */ public void start(BundleContext context) throws Exception { /* Linux user space GPIO implementation, "sysfs" based */ if (System.getProperty("os.name").toLowerCase().startsWith("linux")) { GPIOLinux gpioLinux = new GPIOLinux(); Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put("service.pid", "org.openhab.gpio"); context.registerService(GPIO.class, gpioLinux, null); context.registerService(ManagedService.class, gpioLinux, properties); } else { /* * Throwing exception is not implemented because it's causing Equinox to constantly trying to start the * bundle */ logger.error("No supported operating system was found, GPIO service won't be available"); } }
Example #2
Source File: TelnetServer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void start(BundleContext bc) { TelnetServer.bc = bc; log = new LogRef(bc, true); telnetSessions = new Hashtable<TelnetSession, Thread>(); final Dictionary<String, String> conf = new Hashtable<String, String>(); try { telnetConfig = new TelnetConfig(bc); conf.put(Constants.SERVICE_PID, getClass().getName()); configServReg = bc.registerService(ManagedService.class, this, conf); } catch (final ConfigurationException cexp) { log.error("Consoletelnet configuration error " + cexp.toString()); } telnetServerThread = new Thread(this, "ConsoleTelnetServer"); telnetServerThread.setDaemon(true); telnetServerThread.start(); }
Example #3
Source File: CommandTty.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void start(BundleContext bc) throws Exception { this.bc = bc; log(LogService.LOG_INFO, "Starting"); // Get config Dictionary<String,String> p = new Hashtable<String,String>(); p.put(Constants.SERVICE_PID, getClass().getName()); bc.registerService(ManagedService.class, this, p); inStream = new SystemIn(bc); outStream = System.out; errStream = System.err; cmdProcTracker = new ServiceTracker(bc, CommandProcessor.class, this); cmdProcTracker.open(); logTracker = new ServiceTracker(bc, LogService.class, null); logTracker.open(); }
Example #4
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 #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 |
/** * Update managed services for a deleted targeted PID. This will switch to * another, less specific, targeted configuration if one exists. * * @param targetedPid * the PID of the deleted configuration. * @param oldBundleLocation * the location that the deleted configuration was bound to. * @param pid * the PID of the deleted configuration without target specification. * @param srs * collection of matching (on {@code pid}) managed services. * @throws IOException */ private void updateManagedServicesForDeletedTargetedPID(final String targetedPid, final String oldBundleLocation, final String pid, final Collection<ServiceReference<ManagedService>> srs) throws IOException { { final Collection<ServiceReference<ManagedService>> filtered = filterOnMatchingLocations(srs, oldBundleLocation); for (final ServiceReference<ManagedService> sr : filtered) { if (targetedPidMatches(targetedPid, sr.getBundle())) { // The target specification in the PID of the deleted configuration // matches the bundle owning the current MS, find the currently best // matching configuration if any. ConfigurationDictionary srCd = load(pid, sr.getBundle()); if (srCd != null) { // Found matching configuration, is this a change of configuration? if (targetedPid.length() > srCd.getPid().length()) { // The deleted PID was a better match, must update MS with srCd. srCd = bindLocationIfNecessary(sr, srCd); final String newLocation = srCd.getLocation(); if (!locationsMatch(sr.getBundle(), newLocation)) { // Multi-location region did not match, skip. srCd = null; } } else { srCd = null; } } configurationDispatcher.dispatchUpdateFor(sr, pid, null, srCd); } } } }
Example #7
Source File: HttpServiceTrackerCust.java From cxf with Apache License 2.0 | 5 votes |
@Override public HttpService addingService(ServiceReference<HttpService> reference) { HttpService httpService = context.getService(reference); Servlet servlet = new CXFNonSpringServlet(destinationRegistry, false); servletExporter = new ServletExporter(servlet, httpService); servletPublisherReg = context.registerService(ManagedService.class, servletExporter, CollectionUtils.singletonDictionary(Constants.SERVICE_PID, CXF_CONFIG_PID)); return httpService; }
Example #8
Source File: Activator.java From cxf with Apache License 2.0 | 5 votes |
@Override public void start(BundleContext context) throws Exception { conduitConfigurer = new ConduitConfigurer(context); conduitConfigurer.open(); Dictionary<String, Object> properties = new Hashtable<>(); properties.put(Constants.SERVICE_PID, "org.apache.cxf.transport.http.async"); context.registerService(ManagedService.class.getName(), conduitConfigurer, properties); }
Example #9
Source File: Activator.java From Karaf-Cassandra with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void start(BundleContext context) throws Exception { cassandra = new OsgiEmbeddedCassandra(context); @SuppressWarnings("rawtypes") Dictionary props = new Hashtable(); props.put("service.pid", "de.nierbeck.cassandra.embedded"); cassandraService = context.registerService(new String[] { ManagedService.class.getName(), CassandraService.class.getName() }, cassandra, props); }
Example #10
Source File: Activator.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
private void registerWithConfigAdmin () { logger.info ( "Register with config admin wrapper" ); this.adapter = new StorageManagerAdapter ( this.context ); final Dictionary<String, Object> properties = new Hashtable<> (); properties.put ( Constants.SERVICE_PID, "drone.storage.manager" ); this.adapterHandle = this.context.registerService ( ManagedService.class, this.adapter, properties ); }
Example #11
Source File: Config.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
void register() { if (reg != null) { return; } final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("service.pid", PID); reg = Activator.bc.registerService(ManagedService.class, this, props); }
Example #12
Source File: Config.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
void register() { if (reg != null) { return; } final Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("service.pid", PID); reg = Activator.bc.registerService(ManagedService.class, this, props); }
Example #13
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateManagedService(ServiceReference<ManagedService> sr) throws IOException { // Newly registered managed service; all PIDs are added. final ChangedPids cps = new ChangedPids(); cps.added.addAll(Arrays.asList(getPids(sr))); updateManagedService(sr, cps); }
Example #14
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void updateManagedServices(Collection<ServiceReference<ManagedService>> srs, String servicePid, String boundLocation) { final Collection<ServiceReference<ManagedService>> filtered = filterOnMatchingLocations(srs, boundLocation); for (final ServiceReference<ManagedService> sr : filtered) { configurationDispatcher.dispatchUpdateFor(sr, servicePid, null, null); } }
Example #15
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 #16
Source File: Update.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void update(ManagedService targetService) throws ConfigurationException { if (targetService == null) { return; } targetService.updated(processedConfiguration); }
Example #17
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 #18
Source File: ConsoleTcp.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Called by the framework when this bundle is started. * * @param bc * Bundle context. */ @Override public void start(BundleContext bc) { this.bc = bc; // Get config final Dictionary<String,Object> p = new Hashtable<String,Object>(); p.put(Constants.SERVICE_PID, getClass().getName()); bc.registerService(ManagedService.class.getName(), this, p); }
Example #19
Source File: LogConfigImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
synchronized void start() { dir = initDir((String) configCollection.get(DIR)); final String[] clazzes = new String[]{ManagedService.class.getName(), LogConfig.class.getName()}; bc.registerService(clazzes, this, configCollection); }
Example #20
Source File: ConfigurationAdminFactory.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void updateManagedServicesMatching(final String targetedPid, final String oldBundleLocation) throws IOException { boolean isTargetedPID = false; String pid = targetedPid; Collection<ServiceReference<ManagedService>> srs = getServiceReferencesWithPid(ManagedService.class, pid); if (srs.isEmpty()) { // No MS with the given PID, try to handle it as a targetedPID: final int barPos = targetedPid.indexOf('|'); isTargetedPID = barPos > 0; // At least one char in the PID. if (isTargetedPID) { pid = targetedPid.substring(0, barPos); srs = getServiceReferencesWithPid(ManagedService.class, pid); } } if (srs.isEmpty()) { // No managed services registered for this PID. return; } // Note: We can not filter the set of MSs based on the target specification // in the PID since we must select the most specific matching targeted // configuration for each MS. Thus it may be that we need to update other // MSs with this PID than those that does match on the current target // specification. final boolean isDeleted = null == load(targetedPid, null); if (isDeleted) { if (!isTargetedPID) { // A non-targeted configuration has been deleted, no other configuration // will be available for any matching managed service! updateManagedServices(srs, pid, oldBundleLocation); } else { updateManagedServicesForDeletedTargetedPID(targetedPid, oldBundleLocation, pid, srs); } } else { // New or updated configuration final ServiceReference<ManagedService> bestSr = srs.iterator().next(); final ConfigurationDictionary cd = load(pid, bestSr.getBundle()); final ConfigurationDictionary bound = bindLocationIfNecessary(bestSr, cd); final String newBundleLocation = bound.getLocation(); final Collection<ServiceReference<ManagedService>> filtered = filterOnMatchingLocations(srs, newBundleLocation); for (final ServiceReference<ManagedService> sr : filtered) { ConfigurationDictionary srCd = bound; if (newBundleLocation.charAt(0) == '?') { // There may be another configuration for this SR when multi-locations // are in use! srCd = load(pid, sr.getBundle()); if (!targetedPid.equals(srCd.getPid())) { // This MS uses another targeted configuration than the changed one, // thus no update call. continue; } } configurationDispatcher.dispatchUpdateFor(sr, pid, null, srCd); } } }
Example #21
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 #22
Source File: Activator.java From cxf with Apache License 2.0 | 4 votes |
@Override public void start(final BundleContext bundleContext) { Dictionary<String, String> properties = new Hashtable<>(); properties.put(Constants.SERVICE_PID, CONFIG_PID); bundleContext.registerService(ManagedService.class.getName(), new ConfigUpdater(bundleContext), properties); }