public static <T> ResourceProvider getResourceProvider( ServiceObjects<T> serviceObjects) { CachingServiceReference<T> serviceReference = new CachingServiceReference<>( serviceObjects.getServiceReference()); return new ServiceReferenceResourceProvider( serviceReference, serviceObjects); }
public static <T> OSGi<ServiceTuple<T>> onlyGettables( OSGi<CachingServiceReference<T>> program, Consumer<CachingServiceReference<T>> whenAddedNotGettable, Consumer<CachingServiceReference<T>> whenLeavingNotGettable) { return bundleContext().flatMap(bundleContext -> program.recoverWith( (serviceReference, e) -> notGettableResult( whenAddedNotGettable, whenLeavingNotGettable, serviceReference) ).flatMap(serviceReference -> { ServiceObjects<T> serviceObjects = bundleContext.getServiceObjects( serviceReference.getServiceReference()); T service = serviceObjects.getService(); if (service == null) { return notGettableResult( whenAddedNotGettable, whenLeavingNotGettable, serviceReference); } return onClose( () -> serviceObjects.ungetService(service) ).then( just(new ServiceTuple<>( serviceReference, serviceObjects, service)) ); })); }
public static <T> OSGi<ServiceObjects<T>> serviceObjects( CachingServiceReference<T> immutableServiceReference) { return bundleContext().flatMap(bundleContext -> just(bundleContext.getServiceObjects( immutableServiceReference.getServiceReference())) ); }
ServiceReferenceResourceProvider( CachingServiceReference<?> serviceReference, ServiceObjects<?> serviceObjects) { _serviceReference = serviceReference; _serviceObjects = serviceObjects; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Class<?> getResourceClass() { Object service = _serviceObjects.getService(); try { return service.getClass(); } finally { ((ServiceObjects)_serviceObjects).ungetService(service); } }
ServiceTuple( CachingServiceReference<T> a, ServiceObjects<T> serviceObjects, T service) { _serviceReference = a; _serviceObjects = serviceObjects; _service = service; }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void releaseInstance(Message m, Object o) { ((ServiceObjects)_serviceObjects).ungetService(o); }
public ServiceObjects<T> getServiceObjects() { return _serviceObjects; }
@Override public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> reference) { return null; }