You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by te...@apache.org on 2014/06/17 19:29:55 UTC

git commit: SLIDER-137 Include quick sleep when getting final output

Repository: incubator-slider
Updated Branches:
  refs/heads/develop c61e39013 -> 32b39cffc


SLIDER-137 Include quick sleep when getting final output


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/32b39cff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/32b39cff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/32b39cff

Branch: refs/heads/develop
Commit: 32b39cffcdea15d8683066693585f57562c3a695
Parents: c61e390
Author: tedyu <yu...@gmail.com>
Authored: Tue Jun 17 10:29:54 2014 -0700
Committer: tedyu <yu...@gmail.com>
Committed: Tue Jun 17 10:29:54 2014 -0700

----------------------------------------------------------------------
 .../services/workflow/ForkedProcessService.java   | 18 ++++++++++++++++++
 .../services/workflow/LongLivedProcess.java       |  6 ++++++
 .../TestWorkflowForkedProcessService.java         |  2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/32b39cff/slider-core/src/main/java/org/apache/slider/server/services/workflow/ForkedProcessService.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/services/workflow/ForkedProcessService.java b/slider-core/src/main/java/org/apache/slider/server/services/workflow/ForkedProcessService.java
index 13ed783..b0c503d 100644
--- a/slider-core/src/main/java/org/apache/slider/server/services/workflow/ForkedProcessService.java
+++ b/slider-core/src/main/java/org/apache/slider/server/services/workflow/ForkedProcessService.java
@@ -267,4 +267,22 @@ public class ForkedProcessService extends AbstractWorkflowExecutorService implem
            : new LinkedList<String>();
   }
 
+  /**
+   * Get the recent output from the process, or [] if not defined
+   * @param duration the duration, in ms, which we wait for recent output to become non-empty
+   * @return a possibly empty list
+   */
+  public List<String> getRecentOutput(int duration) {
+    if (process == null) return new LinkedList<String>();
+    long start = System.currentTimeMillis();
+    while (process.isRecentOutputEmpty() && System.currentTimeMillis() - start <= duration) {
+      try {
+        Thread.sleep(20);
+      } catch (InterruptedException ie) {
+        Thread.currentThread().interrupt();
+        break;
+      }
+    }
+    return process.getRecentOutput();
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/32b39cff/slider-core/src/main/java/org/apache/slider/server/services/workflow/LongLivedProcess.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/services/workflow/LongLivedProcess.java b/slider-core/src/main/java/org/apache/slider/server/services/workflow/LongLivedProcess.java
index a1db64f..7b9863f 100644
--- a/slider-core/src/main/java/org/apache/slider/server/services/workflow/LongLivedProcess.java
+++ b/slider-core/src/main/java/org/apache/slider/server/services/workflow/LongLivedProcess.java
@@ -339,6 +339,12 @@ public class LongLivedProcess implements Runnable {
     return new ArrayList<String>(recentLines);
   }
 
+  /*
+   * @return whether lines of recent output are empty
+   */
+  public synchronized boolean isRecentOutputEmpty() {
+    return recentLines.isEmpty();
+  }
 
   /**
    * add the recent line to the list of recent lines; deleting

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/32b39cff/slider-core/src/test/java/org/apache/slider/server/services/workflow/TestWorkflowForkedProcessService.java
----------------------------------------------------------------------
diff --git a/slider-core/src/test/java/org/apache/slider/server/services/workflow/TestWorkflowForkedProcessService.java b/slider-core/src/test/java/org/apache/slider/server/services/workflow/TestWorkflowForkedProcessService.java
index 29d5578..d46f07c 100644
--- a/slider-core/src/test/java/org/apache/slider/server/services/workflow/TestWorkflowForkedProcessService.java
+++ b/slider-core/src/test/java/org/apache/slider/server/services/workflow/TestWorkflowForkedProcessService.java
@@ -118,7 +118,7 @@ public class TestWorkflowForkedProcessService extends WorkflowServiceTestBase {
    * @return the last output
    */
   private List<String> getFinalOutput() {
-    return process.getRecentOutput();
+    return process.getRecentOutput(2000);
   }
 
   private ForkedProcessService initProcess(List<String> commands) throws