Refine search
private void assertThatPluginWithThisExtensionClassLoadsSuccessfully(Class<?> extensionClass) throws IOException, InvalidSyntaxException { BundleContext installedBundleContext = bundleContext(installBundleWithClasses(extensionClass)); ServiceReference<?>[] references = installedBundleContext.getServiceReferences(GoPlugin.class.getName(), null); assertEquals("No service registered for GoPlugin class", 1, references.length); assertEquals("Symbolic Name property should be present", GO_TEST_DUMMY_SYMBOLIC_NAME, references[0].getProperty(Constants.BUNDLE_SYMBOLICNAME)); assertEquals(extensionClass.getName(), installedBundleContext.getService(references[0]).getClass().getName()); }
private void registerService(SomeInterface someInterface, String pluginID, String extension) throws InvalidSyntaxException { ServiceReference<SomeInterface> reference = mock(ServiceReference.class); when(reference.getBundle()).thenReturn(bundle); when(bundle.getSymbolicName()).thenReturn(pluginID); when(bundleContext.getService(reference)).thenReturn(someInterface); when(registry.getPlugin(pluginID)).thenReturn(buildExpectedDescriptor(pluginID)); String propertyFormat = String.format("(&(%s=%s)(%s=%s))", Constants.BUNDLE_SYMBOLICNAME, pluginID, Constants.BUNDLE_CATEGORY, extension); when(bundleContext.getServiceReferences(SomeInterface.class, propertyFormat)).thenReturn(Collections.singletonList(reference)); when(bundleContext.getServiceReferences(SomeInterface.class, null)).thenReturn(Collections.singletonList(reference)); }
public Set<Map.Entry<String, Object>> entrySet() { if (entries != null) { return entries; } Set<Map.Entry<String, Object>> all = new HashSet<Map.Entry<String, Object>>(properties.entrySet()); add: for (String key : service.getPropertyKeys()) { for (String k : properties.keySet()) { if (key.equalsIgnoreCase(k)) { continue add; } } all.add(new Entry(key, service.getProperty(key))); } return entries = Collections.unmodifiableSet(all); }
@Override public ContainerAccessor addingService(ServiceReference<ContainerAccessor> reference) { if (reference.getBundle() == bundle) { return bundle.getBundleContext().getService(reference); } return null; }
private void handleRepositoryXML(ServiceReference<String> reference, String xml) throws Exception { File tempXMLFile = bundleContext.getDataFile("repo-" + reference.getProperty("repository-xml") + ".xml"); writeXMLToFile(tempXMLFile, xml); repoTracker = new ServiceTracker<RepositoryAdmin, RepositoryAdmin>(bundleContext, RepositoryAdmin.class, null); repoTracker.open(); RepositoryAdmin repo = repoTracker.waitForService(30000); repo.addRepository(tempXMLFile.toURI().toURL()); tempXMLFile.delete(); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("repository-populated", reference.getProperty("repository-xml")); bundleContext.registerService(String.class, "", props); }
long registerService() { final Bundle bundle = this.cache.getBundle(); final Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_DESCRIPTION, "Provider of bundle based resources from bundle " + String.valueOf(bundle.getBundleId())); props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); props.put(ResourceProvider.PROPERTY_ROOT, this.root.getResourceRoot()); props.put(PROP_BUNDLE,bundle.getBundleId()); serviceRegistration = bundle.getBundleContext().registerService(ResourceProvider.class, this, props); return (Long) serviceRegistration.getReference().getProperty(Constants.SERVICE_ID); }
@Override public ConfigPusher addingService(ServiceReference<ConfigPusher> configPusherServiceReference) { LOG.trace("Got ConfigPusherCustomizer.addingService {}", configPusherServiceReference); BundleContext bc = configPusherServiceReference.getBundle().getBundleContext(); ConfigPusher cpService = bc.getService(configPusherServiceReference); featureServiceCustomizer = new FeatureServiceCustomizer(cpService); fsst = new ServiceTracker<FeaturesService, FeaturesService>(bc, FeaturesService.class.getName(), featureServiceCustomizer); fsst.open(); return cpService; }
@Override public void run(final ProxyManager pm) throws Exception { String[] objectClassProperty = (String[]) originalRef.getProperty(Constants.OBJECTCLASS); ServiceFactory<Object> sf = new ProxyServiceFactory(pm, originalRef); registrationHolder.registration = originalRef.getBundle().getBundleContext().registerService( objectClassProperty, sf, proxyPropertiesRoles()); Dictionary<String, Object> actualProxyProps = copyProperties(registrationHolder.registration.getReference()); LOG.debug("Created proxy of service {} under {} with properties {}", orgServiceID, actualProxyProps.get(Constants.OBJECTCLASS), actualProxyProps); }
private String getClassName(final ServiceReference sr, final BundleContext context) { if (sr == null) { return null; } if (sr.getProperty("component.name") != null) { // Roo's convention is the component name should be the fully // qualified class name. // Roo's other convention is bundle symbolic names should be fully // qualified package names. // However, the user can change the BSN or component name, so we // need to do a quick sanity check. final String componentName = sr.getProperty("component.name").toString(); if (componentName.startsWith(sr.getBundle().getSymbolicName())) { // The type name appears under the BSN package, so they probably // haven't changed our convention return componentName; } } // To get here we couldn't rely on component name. The following is far // less reliable given the // service may be unavailable by the time we try to do a getService(sr) // invocation (ROO-1156). final Object obj = context.getService(sr); if (obj == null) { return null; } return obj.getClass().getName(); }
public void removedService( final ServiceReference<org.apache.felix.scr.info.ScrInfo> reference, final org.apache.felix.scr.info.ScrInfo service) { final ServiceRegistration<ScrInfo> reg = scrCommandRegMap.remove(reference.getProperty(Constants.SERVICE_ID)); if ( reg != null ) { reg.unregister(); } context.ungetService(reference); } });
@Override public void removedService(ServiceReference serviceReference, Object o) { String appName = (String) serviceReference.getProperty(APPLICATION_NAME); if (!applicationName.equals(appName)) { LOGGER.debug("Applicationname {} does not match service application name {}", appName, applicationName); return; } LOGGER.info("Removing bundle {} to DelegatingClassLoader", serviceReference.getBundle().getSymbolicName()); synchronized (bundles) { bundles.remove(serviceReference); } super.removedService(serviceReference, o); }
private List<HealthCheck> getHealthChecks() throws InvalidSyntaxException { final Collection<ServiceReference<HealthCheck>> serviceReferences = bundleContext.getServiceReferences(HealthCheck.class, null); return serviceReferences.stream() .sorted(Comparator.comparingLong(ref -> ref.getBundle().getBundleId())) .map(ref -> bundleContext.getService(ref)) .collect(Collectors.toList()); }
public String run() { return reference.getBundle().getBundleContext().getProperty("org.osgi.framework.uuid"); } });
public Object addingService(ServiceReference reference) { int rank = 0; Object property = reference.getProperty(Constants.SERVICE_RANKING); if (property instanceof Integer) { rank = (Integer) property; } Object service = bundleContext.getService(reference); ServiceLoader.addService(reference, service, rank); return service; }
private <T> GoPluginDescriptor getDescriptorFor(ServiceReference<T> serviceReference) { String symbolicName = serviceReference.getBundle().getSymbolicName(); return registry.getPlugin(symbolicName); }
public B swap(InstanceCbServiceObjectsServiceObjects<S> swap) { m_dereferenceServiceInternally = false; return setInstanceSwapCallbackRef((inst, component, oref, oserv, nref, nserv) -> swap.accept(oref.getBundle().getBundleContext().getServiceObjects(oref), nref.getBundle().getBundleContext().getServiceObjects(nref))); }
@Override public void removedService(ServiceReference<ContainerAccessor> reference, ContainerAccessor service) { if (reference.getBundle() == bundle) { bundle.getBundleContext().ungetService(reference); } }
private void unregister(ServiceReference reference, ConcurrentMap<Long, ServiceRegistration> mbeans) { Long id = (Long) reference.getProperty(Constants.SERVICE_ID); ServiceRegistration reg = mbeans.remove(id); if (reg != null) reg.unregister(); }
ServiceReference sref = registration.getReference(); String parserFactoryClassName = (String) sref.getProperty(FACTORYNAMEKEY); ((SAXParserFactory) factory).setValidating(((Boolean) sref.getProperty(PARSER_VALIDATING)).booleanValue()); ((SAXParserFactory) factory).setNamespaceAware(((Boolean) sref.getProperty(PARSER_NAMESPACEAWARE)).booleanValue()); } else { if (factory instanceof DocumentBuilderFactory) { ((DocumentBuilderFactory) factory).setValidating(((Boolean) sref.getProperty(PARSER_VALIDATING)).booleanValue()); ((DocumentBuilderFactory) factory).setNamespaceAware(((Boolean) sref.getProperty(PARSER_NAMESPACEAWARE)).booleanValue());
System.out.println("ServiceTracker.getServiceReference: " + filter); ServiceReference<S>[] references = getServiceReferences(); int length = (references == null) ? 0 : references.length; if (length == 0) { /* if no service is being tracked */ int maxRanking = Integer.MIN_VALUE; for (int i = 0; i < length; i++) { Object property = references[i].getProperty(Constants.SERVICE_RANKING); int ranking = (property instanceof Integer) ? ((Integer) property).intValue() : 0; rankings[i] = ranking; for (int i = 0; i < length; i++) { if (rankings[i] == maxRanking) { long id = ((Long) (references[i].getProperty(Constants.SERVICE_ID))).longValue(); if (id < minId) { index = i;