com.googlecode.icegem.utils
Class JavaProcessLauncher

java.lang.Object
  extended by com.googlecode.icegem.utils.JavaProcessLauncher

public class JavaProcessLauncher
extends Object

Platform independent java process launcher.

Author:
Andrey Stepanov aka standy

Field Summary
static long DEFAULT_PROCESS_STARTUP_SHUTDOWN_TIME
          Field DEFAULT_PROCESS_STARTUP_SHUTDOWN_TIME
static String PROCESS_STARTUP_COMPLETED
          Each process that starts with confirmation must write a startup completed string into it's standard output.
 
Constructor Summary
JavaProcessLauncher()
          Constructor JavaProcessLauncher creates a new JavaProcessLauncher instance.
JavaProcessLauncher(boolean redirectProcessInputStreamToParentProcessStdOut, boolean redirectProcessErrorStreamToParentProcessStdOut)
          Constructor JavaProcessLauncher creates a new JavaProcessLauncher instance.
JavaProcessLauncher(boolean redirectProcessInputStreamToParentProcessStdOut, boolean redirectProcessErrorStreamToParentProcessStdOut, boolean printType)
           
 
Method Summary
 int runAndWaitProcessExitCode(Class klass, String[] javaArguments, String[] processArguments)
          Runs process with arguments based on a specified class in a separate VM.
 Process runWithConfirmation(Class klass, String[] javaArguments, String[] processArguments)
          Runs process based on a specified class in a separate VM using array of arguments.
 Process runWithoutConfirmation(Class<?> clazz, String[] javaArguments, String[] processArguments)
          Runs a process and returns the Process object.
 Process runWithStartupDelay(Class klass, String[] javaArguments, String[] processArguments)
          Runs process with arguments based on a specified class in a separate VM.
 Process runWithStartupDelay(Class klass, String[] javaArguments, String[] processArguments, long processStartupTime)
          Runs process with arguments based on a specified class in a separate VM.
 void setRedirectProcessErrorStreamToParentProcessStdOut(boolean redirectProcessErrorStreamToParentProcessStdOut)
          Sets the redirectProcessErrorStreamToParentProcessStdOut of this JavaProcessLauncher object.
 void setRedirectProcessInputStreamToParentProcessStdOut(boolean redirectProcessInputStreamToParentProcessStdOut)
          Sets the redirectProcessInputStreamToParentProcessStdOut of this JavaProcessLauncher object.
 void stopByDestroyingProcess(Process process)
          Stops process by destroying process.
 void stopBySendingNewLineIntoProcess(Process process)
          Stops process by sending new line to it's output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROCESS_STARTUP_COMPLETED

public static final String PROCESS_STARTUP_COMPLETED
Each process that starts with confirmation must write a startup completed string into it's standard output. Only after this command the process startup will be completed.

See Also:
Constant Field Values

DEFAULT_PROCESS_STARTUP_SHUTDOWN_TIME

public static final long DEFAULT_PROCESS_STARTUP_SHUTDOWN_TIME
Field DEFAULT_PROCESS_STARTUP_SHUTDOWN_TIME

See Also:
Constant Field Values
Constructor Detail

JavaProcessLauncher

public JavaProcessLauncher()
Constructor JavaProcessLauncher creates a new JavaProcessLauncher instance.


JavaProcessLauncher

public JavaProcessLauncher(boolean redirectProcessInputStreamToParentProcessStdOut,
                           boolean redirectProcessErrorStreamToParentProcessStdOut)
Constructor JavaProcessLauncher creates a new JavaProcessLauncher instance.

Parameters:
redirectProcessInputStreamToParentProcessStdOut - of type boolean
redirectProcessErrorStreamToParentProcessStdOut - of type boolean

JavaProcessLauncher

public JavaProcessLauncher(boolean redirectProcessInputStreamToParentProcessStdOut,
                           boolean redirectProcessErrorStreamToParentProcessStdOut,
                           boolean printType)
Method Detail

setRedirectProcessErrorStreamToParentProcessStdOut

public void setRedirectProcessErrorStreamToParentProcessStdOut(boolean redirectProcessErrorStreamToParentProcessStdOut)
Sets the redirectProcessErrorStreamToParentProcessStdOut of this JavaProcessLauncher object.

Parameters:
redirectProcessErrorStreamToParentProcessStdOut - boolean flag.

setRedirectProcessInputStreamToParentProcessStdOut

public void setRedirectProcessInputStreamToParentProcessStdOut(boolean redirectProcessInputStreamToParentProcessStdOut)
Sets the redirectProcessInputStreamToParentProcessStdOut of this JavaProcessLauncher object.

Parameters:
redirectProcessInputStreamToParentProcessStdOut - boolean flag.

runAndWaitProcessExitCode

public int runAndWaitProcessExitCode(Class klass,
                                     String[] javaArguments,
                                     String[] processArguments)
                              throws IOException,
                                     InterruptedException
Runs process with arguments based on a specified class in a separate VM. Waits while process is working and returns exit code after process finished.

Parameters:
klass - of type Class
javaArguments - arguments for java
processArguments - arguments for process
Returns:
int
Throws:
IOException - when
InterruptedException - when

runWithoutConfirmation

public Process runWithoutConfirmation(Class<?> clazz,
                                      String[] javaArguments,
                                      String[] processArguments)
                               throws IOException,
                                      InterruptedException
Runs a process and returns the Process object.

Parameters:
clazz - - the class to run
javaArguments - arguments for java
processArguments - arguments for process
Returns:
- the Process object representing running process
Throws:
IOException
InterruptedException

runWithConfirmation

public Process runWithConfirmation(Class klass,
                                   String[] javaArguments,
                                   String[] processArguments)
                            throws IOException,
                                   InterruptedException
Runs process based on a specified class in a separate VM using array of arguments. To confirm that process completes startup it should write a startup completed string into it's standard output.

Parameters:
klass - of type Class
javaArguments - arguments for java
processArguments - arguments for process
Returns:
Process
Throws:
IOException - when
InterruptedException - when

runWithStartupDelay

public Process runWithStartupDelay(Class klass,
                                   String[] javaArguments,
                                   String[] processArguments)
                            throws IOException,
                                   InterruptedException,
                                   TimeoutException
Runs process with arguments based on a specified class in a separate VM. Waits DEFAULT_PROCESS_STARTUP_TIME before returns the created process to a caller.

Parameters:
klass - of type Class
javaArguments - arguments for java
processArguments - arguments for process
Returns:
Process
Throws:
IOException - when
InterruptedException - when
TimeoutException - when

runWithStartupDelay

public Process runWithStartupDelay(Class klass,
                                   String[] javaArguments,
                                   String[] processArguments,
                                   long processStartupTime)
                            throws IOException,
                                   InterruptedException,
                                   TimeoutException
Runs process with arguments based on a specified class in a separate VM. Waits processStartupTime before returns the created process to a caller.

Parameters:
klass - of type Class
processStartupTime - time in milliseconds that launcher spend on waiting process after it's start.
javaArguments - arguments for java
processArguments - arguments for process
Returns:
Process
Throws:
IOException - when
InterruptedException - when
TimeoutException - if process startup is not completed in time.

stopBySendingNewLineIntoProcess

public void stopBySendingNewLineIntoProcess(Process process)
                                     throws IOException,
                                            InterruptedException
Stops process by sending new line to it's output stream. The process can be stopped by calling destroy() method.

Parameters:
process - of type Process
Throws:
IOException - when
InterruptedException

stopByDestroyingProcess

public void stopByDestroyingProcess(Process process)
                             throws IOException
Stops process by destroying process.

Parameters:
process - of type Process
Throws:
IOException - when


Copyright © 2011. All Rights Reserved.