org.osgi.framework.ServiceObjects Java Examples

The following examples show how to use org.osgi.framework.ServiceObjects. 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: ServiceReferenceImpl.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
ServiceObjects<S> getServiceObjects(final Bundle bundle){
	if(service == null)
		return null;  // service already unregistered
	
	if(serviceObjects==null){
		serviceObjects = new HashMap<Bundle, ServiceObjectsImpl>(1);
	}
	
	ServiceObjectsImpl so = serviceObjects.get(bundle);
	if(so == null){
		so = new ServiceObjectsImpl(bundle);
		serviceObjects.put(bundle, so);
	}
	return so;
}
 
Example #2
Source File: ServiceTuple.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
ServiceTuple(
    CachingServiceReference<T> cachingServiceReference,
    ServiceObjects<T> serviceObjects, T service) {

    _serviceReference = cachingServiceReference;
    _serviceObjects = serviceObjects;
    _service = new AtomicReference<>(service);
}
 
Example #3
Source File: Utils.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
public static <T> OSGi<ServiceTuple<T>> onlyGettables(
    OSGi<CachingServiceReference<T>> program,
    Consumer<CachingServiceReference<T>> whenAddedNotGettable,
    Consumer<CachingServiceReference<T>> whenLeavingNotGettable,
    Logger log) {

    return bundleContext().flatMap(bundleContext ->
        program.recoverWith(
            (serviceReference, e) ->
                notGettableResult(
                    whenAddedNotGettable, whenLeavingNotGettable,
                    serviceReference, log)
        ).flatMap(serviceReference -> {
            ServiceObjects<T> serviceObjects =
                bundleContext.getServiceObjects(
                    serviceReference.getServiceReference());
            T service = serviceObjects.getService();

            if (service == null) {
                return notGettableResult(
                    whenAddedNotGettable, whenLeavingNotGettable,
                    serviceReference, log);
            }

            return
                just(new ServiceTuple<>(
                        serviceReference, serviceObjects, service)).
                effects(__ -> {}, ServiceTuple::dispose).
                effects(
                    ifDebugEnabled(
                        log,
                        () -> "Obtained instance from " + serviceReference),
                    ifDebugEnabled(
                        log,
                        () -> "Released instance from " + serviceReference)
                );
        }));
}
 
Example #4
Source File: PrototypeServiceReferenceResourceProvider.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
public PrototypeServiceReferenceResourceProvider(
    CachingServiceReference<?> serviceReference,
    Class<?> serviceClass, ServiceObjects<?> serviceObjects) {

    _serviceReference = serviceReference;
    _serviceClass = serviceClass;
    _serviceObjects = serviceObjects;

    _messageKey = _MESSAGE_INSTANCE_KEY_PREFIX + _serviceClass;
}
 
Example #5
Source File: PrototypeServiceReferenceResourceProvider.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void releaseInstance(Message m, Object o) {
    ((ServiceObjects)_serviceObjects).ungetService(o);

    m.remove(_messageKey);
}
 
Example #6
Source File: BundleContextImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the {@link ServiceObjects} object for the service referenced by
 * the specified {@code ServiceReference} object.
 *
 * @see  org.osgi.framework.BundleContext#getServiceObjects
 */
public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> reference) {
  checkValid();
  bundle.fwCtx.perm.checkGetServicePerms(reference);
  ServiceReferenceImpl<S> sr = (ServiceReferenceImpl<S>)reference;
  if (sr.isAvailable()) {
    return new ServiceObjectsImpl(this, sr);
  }
  return null;
}
 
Example #7
Source File: Netbinox.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> sr) {
    return delegate.getServiceObjects(sr);
}
 
Example #8
Source File: ClassLoaderOsgiFramework.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> serviceReference) {
    throw new UnsupportedOperationException();
}
 
Example #9
Source File: ServiceTuple.java    From aries-jax-rs-whiteboard with Apache License 2.0 4 votes vote down vote up
public ServiceObjects<T> getServiceObjects() {
    return _serviceObjects;
}
 
Example #10
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
public <S> ServiceObjects<S> getServiceObjects(
		final ServiceReference<S> reference) {
	checkValid();

	return ((ServiceReferenceImpl) reference).getServiceObjects(bundle);
}