public String run() { return reference.getBundle().getBundleContext().getProperty("org.osgi.framework.uuid"); } });
private <T> GoPluginDescriptor getDescriptorFor(ServiceReference<T> serviceReference) { String symbolicName = serviceReference.getBundle().getSymbolicName(); return registry.getPlugin(symbolicName); }
final Bundle bundle = service.getBundle(); if (bundle != null) { AccessController.doPrivileged(new PrivilegedAction<Void>() {
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)); }
private void registerServicesWithSameSymbolicName(String symbolicName, String extensionType, SomeInterface... someInterfaces) throws InvalidSyntaxException { ArrayList<ServiceReference<SomeInterface>> references = new ArrayList<>(); for (SomeInterface someInterface : someInterfaces) { ServiceReference<SomeInterface> reference = mock(ServiceReference.class); Bundle bundle = mock(Bundle.class); when(reference.getBundle()).thenReturn(bundle); when(bundle.getSymbolicName()).thenReturn(symbolicName); when(bundleContext.getService(reference)).thenReturn(someInterface); references.add(reference); } String propertyFormat = String.format("(&(%s=%s)(%s=%s))", Constants.BUNDLE_SYMBOLICNAME, symbolicName, Constants.BUNDLE_CATEGORY, extensionType); when(bundleContext.getServiceReferences(SomeInterface.class, propertyFormat)).thenReturn(references); when(registry.getPlugin(symbolicName)).thenReturn(buildExpectedDescriptor(symbolicName)); }
} else { if (trackReference != null) { if (trackReference.getBundle() != null) { @SuppressWarnings("unchecked") ServiceReference<S>[] single = new ServiceReference[] {trackReference};
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(); }
if (trackReference.getBundle() != null) { references = new ServiceReference[] {trackReference};
@Override public String run() { return reference.getBundle().getBundleContext().getProperty("org.osgi.framework.uuid"); } });
@Override public ContainerAccessor addingService(ServiceReference<ContainerAccessor> reference) { if (reference.getBundle() == bundle) { return bundle.getBundleContext().getService(reference); } return null; }
@Override public void removedService(ServiceReference<ContainerAccessor> reference, ContainerAccessor service) { if (reference.getBundle() == bundle) { bundle.getBundleContext().ungetService(reference); } }
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()); }
/** * A new type declaration was published. * * @param reference the service reference of the type declaration * @return the managed type object wrapping the service object. */ public Object addingService(ServiceReference reference) { TypeDeclaration declaration = (TypeDeclaration) m_bundleContext.getService(reference); ManagedType managedType = new ManagedType(reference.getBundle().getBundleContext(), m_queueService, declaration); managedType.start(); return managedType; }
@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); }
@Override public void serviceChanged(ServiceEvent event) { if (event.getType() == ServiceEvent.REGISTERED) { logger.debug(event.getServiceReference().getBundle().getSymbolicName() + " registering service " + displayClass(event.getServiceReference())); } else if (event.getType() == ServiceEvent.UNREGISTERING) { logger.debug(event.getServiceReference().getBundle().getSymbolicName() + " unregistering service " + displayClass(event.getServiceReference())); } else { logger.debug("Modifying service " + event.getServiceReference()); } }
private void computeInterceptorDescription(ServiceReference ref, Element itcp) { itcp.addAttribute(new Attribute(Constants.SERVICE_ID, ref.getProperty(Constants.SERVICE_ID).toString())); itcp.addAttribute(new Attribute("bundle.id", Long.toString(ref.getBundle().getBundleId()))); String instance = (String) ref.getProperty(Factory.INSTANCE_NAME_PROPERTY); if (instance != null) { itcp.addAttribute(new Attribute(Factory.INSTANCE_NAME_PROPERTY, instance)); } itcp.addAttribute(new Attribute("target", ref.getProperty(ServiceTrackingInterceptor.TARGET_PROPERTY) .toString())); }
public void removedService(final ServiceReference serviceReference, final Object o) { if (serviceReference.getBundle() == bundle) { final ModuleDescriptor<?> descriptor = (ModuleDescriptor<?>) o; pluginEventManager.broadcast(new PluginModuleUnavailableEvent(descriptor)); plugin.clearModuleDescriptor(descriptor.getKey()); if (log.isInfoEnabled()) { log.info("Dynamically removed module descriptor: " + descriptor.getCompleteKey()); } } } }
@Override public void call(Object hook, ServiceRegistration<?> hookRegistration) throws Exception { if (!(hook instanceof WovenClassListener)) return; try { ((WovenClassListener) hook).modified(WovenClassImpl.this); } catch (Exception e) { WovenClassImpl.this.container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, hookRegistration.getReference().getBundle(), e); } }
/** * ServiceListener.serviceChanged method. * */ public void serviceChanged(ServiceEvent event) { ServiceReference<?> reference = event.getServiceReference(); Bundle bundle = reference.getBundle(); int eventType = event.getType(); int logType = (eventType == ServiceEvent.MODIFIED) ? LogService.LOG_DEBUG : LogService.LOG_INFO; if (logReaderServiceFactory.isLoggable(bundle, null, logType)) logReaderServiceFactory.log(bundle, null, reference, logType, getServiceEventTypeName(eventType), null); }
protected void removeService( final ManagedServiceHolder holder ) { MetaTypeInformationImpl mti = getMetaTypeInformationInternal( holder.getReference().getBundle() ); if ( mti != null ) { mti.removeService( holder.getPids(), holder.isSingleton(), holder.isFactory() ); } }