Java Code Examples for org.osgi.util.promise.Deferred#getPromise()

The following examples show how to use org.osgi.util.promise.Deferred#getPromise() . 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: TestAsyncResource.java    From aries-jax-rs-whiteboard with Apache License 2.0 6 votes vote down vote up
@GET
@Path("promise/{name}")
@Produces(MediaType.TEXT_PLAIN)
public Promise<String> echoPromise(@PathParam("name") String value) {
    
    Deferred<String> d = new Deferred<>();
    
    new Thread(() -> {
        try {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                preResume.run();
                d.fail(e);
                return;
            }
            preResume.run();
            d.resolve(value);
        } finally {
            postResume.run();
        }
    }).start();
    
    return d.getPromise();
}
 
Example 2
Source File: PromiseRxInvokerImpl.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public <R> Promise<R> method(
    String s, Entity<?> entity, GenericType<R> genericType) {

        Deferred<R> deferred = _promiseFactory.deferred();
    
    _webClient.doInvokeAsync(s, entity, null, null, genericType.getRawType(), genericType.getType(), 
            new DeferredHandler<R>(deferred));

    return deferred.getPromise();
}
 
Example 3
Source File: PromiseRxInvokerImpl.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public <R> Promise<R> method(String s, GenericType<R> genericType) {
    Deferred<R> deferred = _promiseFactory.deferred();
    
    _webClient.doInvokeAsync(s, null, null, null, genericType.getRawType(), genericType.getType(), 
            new DeferredHandler<R>(deferred));

    return deferred.getPromise();
}
 
Example 4
Source File: RepositoryImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Promise<Collection<Resource>> findProviders(RequirementExpression expression) {
  Deferred<Collection<Resource>> d = new Deferred<Collection<Resource>>();
  try {
    new ExpressionResolver(this, expression, d).start();
  } catch (Exception e) {
    d.fail(e);
  }
  return d.getPromise();
}
 
Example 5
Source File: ServiceComponentRuntimeImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  {@inheritDoc}
 */
public Promise<Void> enableComponent(ComponentDescriptionDTO description) {
  Component c = getComponent(description);
  Deferred<Void> d = new Deferred<Void>();
  if (c != null) {
    c.enable(d);
  } else {
    d.fail(new IllegalArgumentException("Unknown component"));
  }
  return d.getPromise();
}
 
Example 6
Source File: ServiceComponentRuntimeImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  {@inheritDoc}
 */
public Promise<Void> disableComponent(ComponentDescriptionDTO description) {
  Component c = getComponent(description);
  Deferred<Void> d = new Deferred<Void>();
  if (c != null) {
    c.disable(d);
  } else {
    d.fail(new IllegalArgumentException("Unknown component"));
  }
  return d.getPromise();
}
 
Example 7
Source File: PromiseRxInvokerImpl.java    From aries-jax-rs-whiteboard with Apache License 2.0 3 votes vote down vote up
@Override
public <R> Promise<R> method(String s, Class<R> responseType) {
    
        Deferred<R> deferred = _promiseFactory.deferred();
    
        _webClient.doInvokeAsync(s, null, null, null, responseType, responseType, 
                new DeferredHandler<R>(deferred));
    
    return deferred.getPromise();
}
 
Example 8
Source File: PromiseRxInvokerImpl.java    From aries-jax-rs-whiteboard with Apache License 2.0 3 votes vote down vote up
@Override
public <R> Promise<R> method(String s, Entity<?> entity, Class<R> responseType) {
    
    Deferred<R> deferred = _promiseFactory.deferred();

    _webClient.doInvokeAsync(s, entity, null, null, responseType, responseType, 
            new DeferredHandler<R>(deferred));

return deferred.getPromise();
}