Class 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 Detail

      • AsyncProxyDelegate

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

      • 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
      • 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).
        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