[ 
https://issues.apache.org/jira/browse/HADOOP-12910?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15317739#comment-15317739
 ] 

Tsz Wo Nicholas Sze commented on HADOOP-12910:
----------------------------------------------

It seems we all agree that we should use CompletableFuture (a Java 8 class 
which implements both Future and CompletionStage) with callback support as a 
return type in trunk.  Since we are talking about API, we should actually talk 
about interfaces instead of classes.  Therefore, we should return an 
sub-interface of Future and CompletionStage.

For branch-2, There are two possible ways to use Deferred (or ListenableFuture) 
:
# Using it directly (i.e. import the external jar and use 
com.stumbleupon.async.Deferred in the code).  Then we have an external 
dependency.
# Copy & Paste Deferred to Hadoop, say 
org.apache.hadoop.util.concurrent.Deferred.  Then we can the Deferred 
functionality but our Deferred is incompatible of the 
com.stumbleupon.async.Deferred used in the other projects.  Also, it may be 
harder to support CompletableFuture in trunk since we have to support both 
Deferred and CompletableFuture.

Both choices seem undesirable. Therefore I suggest to create our own interface 
to support callbacks for branch-2 as below.
{code}
  public interface Callback<V> {
    void processReturnValue(V returnValue);

    void handleException(Exception exception);
  }

  // branch-2 return type
  public interface FutureWithCallback<V> extends Future<V> {
    void addCallback(Callback<V> callback);
  }
{code}
For trunk, we have
{code}
  // trunk return type
  public interface CompletableFutureWithCallback<V>
      extends FutureWithCallback<V>, CompletionStage<V> {
  }
{code}
Any comments?

> Add new FileSystem API to support asynchronous method calls
> -----------------------------------------------------------
>
>                 Key: HADOOP-12910
>                 URL: https://issues.apache.org/jira/browse/HADOOP-12910
>             Project: Hadoop Common
>          Issue Type: New Feature
>          Components: fs
>            Reporter: Tsz Wo Nicholas Sze
>            Assignee: Xiaobing Zhou
>         Attachments: HADOOP-12910-HDFS-9924.000.patch, 
> HADOOP-12910-HDFS-9924.001.patch, HADOOP-12910-HDFS-9924.002.patch
>
>
> Add a new API, namely FutureFileSystem (or AsynchronousFileSystem, if it is a 
> better name).  All the APIs in FutureFileSystem are the same as FileSystem 
> except that the return type is wrapped by Future, e.g.
> {code}
>   //FileSystem
>   public boolean rename(Path src, Path dst) throws IOException;
>   //FutureFileSystem
>   public Future<Boolean> rename(Path src, Path dst) throws IOException;
> {code}
> Note that FutureFileSystem does not extend FileSystem.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to