You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/23 19:47:36 UTC

[10/20] incubator-ignite git commit: #ignite-965: code style GridJavaProcess.

#ignite-965: code style GridJavaProcess.


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

Branch: refs/heads/ignite-965
Commit: d67b15a2fdb25045c005f752bb55422fdb481312
Parents: a28b02d
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 23 19:57:30 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 23 19:57:30 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/util/GridJavaProcess.java   | 46 +++++++++-----------
 1 file changed, 21 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d67b15a2/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
index 693d486..a854f82 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridJavaProcess.java
@@ -120,14 +120,6 @@ public final class GridJavaProcess {
     public static GridJavaProcess exec(String clsName, String params, @Nullable IgniteLogger log,
         @Nullable IgniteInClosure<String> printC, @Nullable GridAbsClosure procKilledC,
         @Nullable Collection<String> jvmArgs, @Nullable String cp) throws Exception {
-        if (!(U.isLinux() || U.isMacOs() || U.isWindows()))
-            throw new Exception("Your OS is not supported.");
-
-        GridJavaProcess gjProc = new GridJavaProcess();
-
-        gjProc.log = log;
-        gjProc.procKilledC = procKilledC;
-
         List<String> procParams = params == null || params.isEmpty() ?
             Collections.<String>emptyList() : Arrays.asList(params.split(" "));
 
@@ -160,17 +152,7 @@ public final class GridJavaProcess {
 
         builder.redirectErrorStream(true);
 
-        Process proc = builder.start();
-
-        gjProc.osGrabber = gjProc.new ProcessStreamGrabber(proc.getInputStream(), printC);
-        gjProc.esGrabber = gjProc.new ProcessStreamGrabber(proc.getErrorStream(), printC);
-
-        gjProc.osGrabber.start();
-        gjProc.esGrabber.start();
-
-        gjProc.proc = proc;
-
-        return gjProc;
+        return setGrabber(builder, log, printC, procKilledC);
     }
 
     /**
@@ -187,7 +169,27 @@ public final class GridJavaProcess {
     public static GridJavaProcess exec(List<String> cmd, Map<String, String> env, @Nullable IgniteLogger log,
         @Nullable IgniteInClosure<String> printC, @Nullable GridAbsClosure procKilledC)
         throws Exception {
+        ProcessBuilder builder = new ProcessBuilder(cmd);
 
+        builder.redirectErrorStream(true);
+
+        builder.environment().putAll(env);
+
+        return setGrabber(builder, log, printC, procKilledC);
+    }
+
+
+    /**
+     * @param builder Process builder.
+     * @param log Log to use.
+     * @param printC Optional closure to be called each time wrapped process prints line to system.out or system.err.
+     * @param procKilledC Optional closure to be called when process termination is detected.
+     * @return Wrapper around {@link Process}
+     * @throws Exception If any problem occurred.
+     */
+    private static GridJavaProcess setGrabber(ProcessBuilder builder,
+        @Nullable IgniteLogger log, @Nullable IgniteInClosure<String> printC,
+        @Nullable GridAbsClosure procKilledC) throws Exception {
         if (!(U.isLinux() || U.isMacOs() || U.isWindows()))
             throw new Exception("Your OS is not supported.");
 
@@ -196,12 +198,6 @@ public final class GridJavaProcess {
         gjProc.log = log;
         gjProc.procKilledC = procKilledC;
 
-        ProcessBuilder builder = new ProcessBuilder(cmd);
-
-        builder.redirectErrorStream(true);
-
-        builder.environment().putAll(env);
-
         Process proc = builder.start();
 
         gjProc.osGrabber = gjProc.new ProcessStreamGrabber(proc.getInputStream(), printC);