Class AsyncProxyDelegate<S>

java.lang.Object
org.gcube.common.clients.delegates.AsyncProxyDelegate<S>
Type Parameters:
S - the type of service stubs
All Implemented Interfaces:
ProxyDelegate<S>

public class AsyncProxyDelegate<S> extends Object implements ProxyDelegate<S>
A ProxyDelegate that delivers the outcome of Calls asynchronously, either through polling or notifications.

The delegates use ExecutorServices to make calls in separate threads. If required, clients may provide their own ExecutorServices at the point of call submission.

Author:
Fabio Simeoni
  • Constructor Details

    • AsyncProxyDelegate

      public AsyncProxyDelegate(ProxyDelegate<S> delegate)
      Creates an instance with a (synchronous) ProxyDelegate
      Parameters:
      delegate - the delegate
  • Method Details

    • make

      public <V> V make(Call<S,V> call) throws Exception
      Description copied from interface: ProxyDelegate
      Makes a Call to a given service endpoint.
      Specified by:
      make in interface ProxyDelegate<S>
      Type Parameters:
      V - the type of the value returned from the call
      Parameters:
      call - the call
      Returns:
      the value returned from the call
      Throws:
      Exception - if the call fails
    • config

      public ProxyConfig<?,S> config()
      Description copied from interface: ProxyDelegate
      Returns the configuration of the proxy.
      Specified by:
      config in interface ProxyDelegate<S>
      Returns:
      the configuration
    • makeAsync

      public <V> Future<V> makeAsync(Call<S,V> call) throws RejectedExecutionException
      Makes a Call to a service endpoint asynchronously, returning a Future that clients can use to poll for and obtain the call outcome, or to cancel the call (assuming that the call is designed for cancellation or has not been made yet).
      Type Parameters:
      V - the type of the value returned from the Call
      Parameters:
      call - the Call to be made asynchronously
      Returns:
      the Future of the Call outcome
      Throws:
      RejectedExecutionException - if the call cannot not be submitted for asynchronous execution
    • makeAsync

      public <V> Future<V> makeAsync(Call<S,V> call, ExecutorService service) throws RejectedExecutionException
      Makes a Call to a service endpoint asynchronously, returning a Future that clients can use to poll for and obtain the call outcome, or to cancel the call (assuming that the call is designed for cancellation or has not been made yet).
      Type Parameters:
      V - the type of the value returned from the Call
      Parameters:
      call - the Call to be executed asynchronously
      service - a ExecutorService to which the Call should be submitted for execution
      Returns:
      the Future of the Call outcome
      Throws:
      RejectedExecutionException - if the call cannot not be submitted for asynchronous execution
    • makeAsync

      public <V> Future<?> makeAsync(Call<S,V> call, Callback<V> callback) throws RejectedExecutionException
      Makes a Call to a service endpoint asynchronously, notifying a Callback of its outcome. Returns a Future that clients can use to cancel the execution of the call (assuming that the call is designed for cancellation or has not been made yet).
      Type Parameters:
      V - the type of the value returned from the Call
      Parameters:
      call - the Call
      callback - the Callback
      Returns:
      the Future of call submission
      Throws:
      RejectedExecutionException - if the call cannot not be submitted for asynchronous execution
    • makeAsync

      public <V> Future<?> makeAsync(Call<S,V> call, Callback<V> callback, ExecutorService service) throws RejectedExecutionException
      Makes a Call to a service endpoint asynchronously, notifying a Callback of its outcome. Returns a Future that clients can use to cancel the execution of the call (assuming that the call is designed for cancellation or has not been made yet).
      Type Parameters:
      V - the type of the value returned from the Call
      Parameters:
      call - the Call
      callback - the Callback
      service - the ExecutorService that executes the call
      Returns:
      the Future of call submission
      Throws:
      RejectedExecutionException - if the call cannot not be submitted for asynchronous execution