org.gcube.common.clients.delegates
Class AsyncProxyDelegate<S>

java.lang.Object
  extended by 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 Summary
AsyncProxyDelegate(ProxyDelegate<S> delegate)
          Creates an instance with a (synchronous) ProxyDelegate
 
Method Summary
 ProxyConfig<?,S> config()
          Returns the configuration of the proxy.
<V> V
make(Call<S,V> call)
          Makes a Call to a given service endpoint.
<V> Future<V>
makeAsync(Call<S,V> call)
          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).
<V> Future<?>
makeAsync(Call<S,V> call, Callback<V> callback)
          Makes a Call to a service endpoint asynchronously, notifying a Callback of its outcome.
<V> Future<?>
makeAsync(Call<S,V> call, Callback<V> callback, ExecutorService service)
          Makes a Call to a service endpoint asynchronously, notifying a Callback of its outcome.
<V> Future<V>
makeAsync(Call<S,V> call, ExecutorService service)
          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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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

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

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


Copyright © 2012. All Rights Reserved.