diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-08-19 13:37:35 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-08-19 13:37:35 +0530 |
| commit | 9fdc4e3e7213544a4813e81ac778e38747f9b002 (patch) | |
| tree | 52c355c835c9f269ec47eb05783a5397f13c1747 /src | |
| parent | 98c87e32fb110a99c6079c88560662a7c6457144 (diff) | |
Introduced method waitForThreads and made all methods static
Diffstat (limited to 'src')
| -rw-r--r-- | src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java index becd46a7..cd9d2549 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/ProcessUtil.java @@ -24,7 +24,6 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; @@ -35,18 +34,32 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; */ public class ProcessUtil { - private static final ProcessUtil instance = new ProcessUtil(); - - public ProcessResult executeCommand(List<String> command) { + public static ProcessResult executeCommand(List<String> command) { return executeCommand(true, command); } + /** + * Waits till all the threads in given list are dead + * @param threads Threads to watch + * @throws InterruptedException + */ + public static void waitForThreads(List<Thread> threads) throws InterruptedException { + // Wait till all servers have been processed + for (int i = threads.size() - 1; i >= 0; i--) { + if (threads.get(i).isAlive()) { + // thread alive. sleep for half a second and check again. + Thread.sleep(500); + i++; // check the same thread in next iteration + } + } + } + /** * Executes given command in a separate process in FOREGROUND * @param command * @return {@link ProcessResult} object */ - public ProcessResult executeCommand(String... command) { + public static ProcessResult executeCommand(String... command) { ArrayList<String> commandList = new ArrayList<String>(); for (String part : command) { commandList.add(part); @@ -61,7 +74,7 @@ public class ProcessUtil { * @param command * @return {@link ProcessResult} object */ - public ProcessResult executeCommand(boolean runInForeground, List<String> command) { + public static ProcessResult executeCommand(boolean runInForeground, List<String> command) { StringBuilder output = new StringBuilder(); try { Process process = new ProcessBuilder(command).redirectErrorStream(true).start(); @@ -89,10 +102,4 @@ public class ProcessUtil { + e.getMessage() + "]", e); } } - - public static void main(String args[]) { - ProcessResult result = new ProcessUtil().executeCommand("ls", "-lrt", "/"); - System.out.println(result.getExitValue()); - System.out.println(result.getOutput()); - } } |
