public boolean isAssignableTo(Bundle bundle, String className) { return m_origin.isAssignableTo(bundle, className); }
/** * Determine if the reference binds to a specified class in a specified * bundle * @param bundle the bundle * @param className the class * @return true if the reference binds to a specified class in a specified * bundle */ @Override public boolean isAssignableTo(Bundle bundle, String className) { return myReference.isAssignableTo(bundle, className); }
public boolean isAssignableTo(Bundle bundle, String className) { return m_origin.isAssignableTo(bundle, className); }
@Override public boolean match(ServiceReference<?> reference) { return reference.isAssignableTo(systemBundle, className); }
@Override public boolean isAssignableTo(final Bundle bundle, final String className) { return delegate != null && delegate.isAssignableTo(bundle, className); }
@Override public boolean isAssignableTo(final Bundle bundle, final String className) { return delegate != null && delegate.isAssignableTo(bundle, className); }
public boolean isAssignableTo(Bundle bundle, String className) { return target.isAssignableTo(bundle, className); }
public synchronized boolean isAssignableTo(Bundle bundle, String className) { return (delegate == null ? false : delegate.isAssignableTo(bundle, className)); }
if (!ref.isAssignableTo(requester, objectClass[classIdx]))
/** * This method determines if the requesting bundle is able to cast * the specified service reference based on class visibility rules * of the underlying modules. * @param requester The bundle requesting the service. * @param ref The service in question. * @return <tt>true</tt> if the requesting bundle is able to case * the service object to a known type. **/ public static boolean isServiceAssignable(Bundle requester, ServiceReference ref) { // Boolean flag. boolean allow = true; // Get the service's objectClass property. String[] objectClass = (String[]) ref.getProperty(FelixConstants.OBJECTCLASS); // The the service reference is not assignable when the requesting // bundle is wired to a different version of the service object. // NOTE: We are pessimistic here, if any class in the service's // objectClass is not usable by the requesting bundle, then we // disallow the service reference. for (int classIdx = 0; (allow) && (classIdx < objectClass.length); classIdx++) { if (!ref.isAssignableTo(requester, objectClass[classIdx])) { allow = false; } } return allow; }
/** * This method determines if the requesting bundle is able to cast * the specified service reference based on class visibility rules * of the underlying modules. * @param requester The bundle requesting the service. * @param ref The service in question. * @return <tt>true</tt> if the requesting bundle is able to case * the service object to a known type. **/ public static boolean isServiceAssignable(Bundle requester, ServiceReference ref) { // Boolean flag. boolean allow = true; // Get the service's objectClass property. String[] objectClass = (String[]) ref.getProperty(FelixConstants.OBJECTCLASS); // The the service reference is not assignable when the requesting // bundle is wired to a different version of the service object. // NOTE: We are pessimistic here, if any class in the service's // objectClass is not usable by the requesting bundle, then we // disallow the service reference. for (int classIdx = 0; (allow) && (classIdx < objectClass.length); classIdx++) { if (!ref.isAssignableTo(requester, objectClass[classIdx])) { allow = false; } } return allow; }
if (!ref.isAssignableTo(requester, objectClass[classIdx]))
private void foundUserAdmin(final ServiceReference reference) { try { Class.forName(USER_ADMIN); if (reference.isAssignableTo(ctx.getBundle(), USER_ADMIN)) { registerMBean(UserAdminMBean.class.getName(), new Factory<UserAdminMBean>() { public UserAdminMBean create() { UserAdmin service = (UserAdmin) ctx.getService(reference); if (service == null) return null; else return new org.apache.aries.jmx.useradmin.UserAdmin(service); } }, UserAdminMBean.OBJECTNAME, _userAdminMBeans, reference, USER_ADMIN); } } catch (ClassNotFoundException e) { } }
private <T> void registerMBean(String type, Factory<T> factory, String objectName, ConcurrentMap<Long, ServiceRegistration> mbeans, ServiceReference referencedServices, String underlyingType) { try { Class.forName(underlyingType); if (referencedServices.isAssignableTo(ctx.getBundle(), underlyingType)) { ServiceRegistration reg = registerAnMbean(type, factory, objectName); Long id = (Long) reg.getReference().getProperty(Constants.SERVICE_ID); mbeans.put(id, reg); } } catch (ClassNotFoundException e) { } }
@Override public LogService addingService(ServiceReference<LogService> reference) { if (reference.isAssignableTo(bundleContext.getBundle(), "org.osgi.service.log.LogService")) { LogService logService = bundleContext.getService(reference); try { if (logService instanceof LogService) { LogService old = logServiceReference.getAndSet(logService); if (old != null) { LOG.debug( "replace old LogService instance {} by an instance of {}", old.getClass().getName(), logService.getClass() .getName()); } return logService; } } catch (NoClassDefFoundError e) { LOG.warn("A LogService service was found, but the coresponding class can't be loaded, make sure to have a compatible org.osgi.service.log package package exported with version range [1.3,2.0)"); } // If we came along here, we have no use of this service, so unget // it! bundleContext.ungetService(reference); } else { LOG.warn("A LogService service was found, but it is not assignable to this bundle, make sure to have a compatible org.osgi.service.log package package exported with version range [1.3,2.0)"); } return null; }
@Override public EventAdmin addingService(ServiceReference<EventAdmin> reference) { if (reference.isAssignableTo(bundleContext.getBundle(), "org.osgi.service.event.EventAdmin")) { EventAdmin eventService = bundleContext.getService(reference); try { if (eventService instanceof EventAdmin) { EventAdmin old = eventAdminReference .getAndSet(eventService); if (old != null) { LOG.debug( "replace old EventAdmin instance {} by an instance of {}", old.getClass().getName(), eventService .getClass().getName()); } return eventService; } } catch (NoClassDefFoundError e) { LOG.warn("An EventAdmin service was found, but the corresponding class can't be loaded, make sure to have a compatible org.osgi.service.event package exported with version range [1.3,2.0)"); } // If we came along here, we have no use of this service, so unget // it! bundleContext.ungetService(reference); } else { LOG.warn("An EventAdmin service was found, but it is not assignable to this bundle, make sure to have a compatible org.osgi.service.event package exported with version range [1.3,2.0)"); } return null; }
/** * Static helper method to get a {@link OsgiServiceProxy} {@link Proxy} * * @param tracker the {@link ServiceTracker} to get a {@link Proxy} for * @param type the {@link Class} type of the Service Object * @return the {@link Proxy} */ @SuppressWarnings("unchecked") public static <T> T getServiceProxy(ServiceTracker tracker, Class<T> type) { ServiceReference reference = tracker.getServiceReference(); if (reference.isAssignableTo(reference.getBundle(), type.getName())) { InvocationHandler handler = new OsgiServiceProxy(tracker); return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler); } else { throw new OsgiContainerException("Service '" + reference.getBundle().getClass() + "' is not of type " + type); } }
String[] list = (String[]) reference.getProperty(Constants.OBJECTCLASS); for (int i = 0; i < list.length; i++) { if (!reference.isAssignableTo(m_context.getBundle(), list[i])) { iterator.remove(); break;
@Override public void serviceChanged(ServiceEvent event) { if (bundleContext == null) { // already deactivated? return; } ServiceReference serviceReference = event.getServiceReference(); final boolean isHealthCheck = serviceReference.isAssignableTo(bundleContext.getBundle(), HealthCheck.class.getName()); if (isHealthCheck) { HealthCheckMetadata healthCheckMetadata = new HealthCheckMetadata(serviceReference); int eventType = event.getType(); if (eventType == ServiceEvent.REGISTERED) { LOG.debug("Received service event REGISTERED for health check {}", healthCheckMetadata); scheduleHealthCheck(healthCheckMetadata); } else if (eventType == ServiceEvent.UNREGISTERING) { LOG.debug("Received service event UNREGISTERING for health check {}", healthCheckMetadata); unscheduleHealthCheck(healthCheckMetadata); } else if (eventType == ServiceEvent.MODIFIED) { LOG.debug("Received service event MODIFIED for health check {}", healthCheckMetadata); unscheduleHealthCheck(healthCheckMetadata); scheduleHealthCheck(healthCheckMetadata); } } }
@Override public void serviceChanged(ServiceEvent event) { if(bundleContext == null) { // already deactivated? return; } ServiceReference serviceReference = event.getServiceReference(); final boolean isHealthCheck = serviceReference.isAssignableTo(bundleContext.getBundle(), HealthCheck.class.getName()); if (isHealthCheck) { HealthCheckMetadata healthCheckMetadata = new HealthCheckMetadata(serviceReference); int eventType = event.getType(); LOG.debug("Received service event of type {} for health check {}", eventType, healthCheckMetadata); if (eventType == ServiceEvent.REGISTERED) { scheduleHealthCheck(healthCheckMetadata); } else if (eventType == ServiceEvent.UNREGISTERING) { unscheduleHealthCheck(healthCheckMetadata); } else if (eventType == ServiceEvent.MODIFIED) { unscheduleHealthCheck(healthCheckMetadata); scheduleHealthCheck(healthCheckMetadata); } } }