You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by yu...@apache.org on 2015/11/23 08:57:29 UTC

incubator-reef git commit: [REEF-1011] Use Optional in favor of null check in VortexFuture

Repository: incubator-reef
Updated Branches:
  refs/heads/master 8c934243f -> 8dbce4708


[REEF-1011] Use Optional in favor of null check in VortexFuture

JIRA:
  [REEF-1011](https://issues.apache.org/jira/browse/REEF-1011)

Pull Request:
  This closes #675


Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/8dbce470
Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/8dbce470
Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/8dbce470

Branch: refs/heads/master
Commit: 8dbce4708c15b0e4ba119ac3cf0095e0debc8584
Parents: 8c93424
Author: Andrew Chung <af...@gmail.com>
Authored: Sun Nov 22 22:42:09 2015 -0800
Committer: Yunseong Lee <yu...@apache.org>
Committed: Mon Nov 23 15:56:18 2015 +0800

----------------------------------------------------------------------
 .../java/org/apache/reef/vortex/api/VortexFuture.java  | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/8dbce470/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java b/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
index 26ff509..7b84b19 100644
--- a/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
+++ b/lang/java/reef-applications/reef-vortex/src/main/java/org/apache/reef/vortex/api/VortexFuture.java
@@ -19,6 +19,7 @@
 package org.apache.reef.vortex.api;
 
 import org.apache.reef.annotations.Unstable;
+import org.apache.reef.util.Optional;
 import org.apache.reef.wake.EventHandler;
 import org.apache.reef.wake.impl.ThreadPoolStage;
 
@@ -29,7 +30,9 @@ import java.util.concurrent.*;
  */
 @Unstable
 public final class VortexFuture<TOutput> implements Future<TOutput> {
-  private TOutput userResult;
+  // userResult starts out as null. If not null => variable is set and tasklet returned.
+  // Otherwise tasklet has not completed.
+  private Optional<TOutput> userResult = null;
   private Exception userException;
   private final CountDownLatch countDownLatch = new CountDownLatch(1);
   private final ThreadPoolStage<TOutput> stage;
@@ -79,7 +82,7 @@ public final class VortexFuture<TOutput> implements Future<TOutput> {
   public TOutput get() throws InterruptedException, ExecutionException {
     countDownLatch.await();
     if (userResult != null) {
-      return userResult;
+      return userResult.get();
     } else {
       assert userException != null;
       throw new ExecutionException(userException);
@@ -97,7 +100,7 @@ public final class VortexFuture<TOutput> implements Future<TOutput> {
     }
 
     if (userResult != null) {
-      return userResult;
+      return userResult.get();
     } else {
       assert userException != null;
       throw new ExecutionException(userException);
@@ -108,9 +111,9 @@ public final class VortexFuture<TOutput> implements Future<TOutput> {
    * Called by VortexMaster to let the user know that the task completed.
    */
   public void completed(final TOutput result) {
-    this.userResult = result;
+    this.userResult = Optional.ofNullable(result);
     if (stage != null) {
-      stage.onNext(userResult);
+      stage.onNext(userResult.get());
     }
     this.countDownLatch.countDown();
   }