org.icenigrid.gridsam.core.plugin.shell
Class AbstractShell

java.lang.Object
  extended byorg.icenigrid.gridsam.core.plugin.shell.AbstractShell
All Implemented Interfaces:
Shell
Direct Known Subclasses:
POSIXShell

public abstract class AbstractShell
extends Object
implements Shell

Abstract implementation of Shell


Nested Class Summary
protected  class AbstractShell.PipeRunnable
          a runnable that takes input from an ReadableByteChannel and write the input to the WritableByteChannel
 
Field Summary
protected static int STDERR
          id for standard error stream
protected static int STDOUT
          id for standard output stream
 
Constructor Summary
AbstractShell()
           
 
Method Summary
 int executeCommand(String pCommandString, File pProcessRoot, Properties pEnv)
          execute a system process synchronously.
 int executeCommand(String pCommandString, File pProcessRoot, Properties pEnv, CommandListener pListener)
          execute a command synchronously.
 int executeCommand(String pCommandString, File pProcessRoot, Properties pEnv, File pStdOut, File pStdErr)
          execute a command synchronously.
 Process executeCommandAsynchronously(String pCommandString, File pProcessRoot, Properties pEnv)
          execute a system process asynchronously.
protected  Thread pipeStream(InputStream pInputStream, int pStream, CommandListener pListener)
          pipe the input of a stream to the output
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.icenigrid.gridsam.core.plugin.shell.Shell
close, executeCommand, executeCommandAsynchronously, executeCommandAsynchronously, executeCommandAsynchronously, getFileSystem
 

Field Detail

STDOUT

protected static final int STDOUT
id for standard output stream

See Also:
Constant Field Values

STDERR

protected static final int STDERR
id for standard error stream

See Also:
Constant Field Values
Constructor Detail

AbstractShell

public AbstractShell()
Method Detail

executeCommandAsynchronously

public Process executeCommandAsynchronously(String pCommandString,
                                            File pProcessRoot,
                                            Properties pEnv)
                                     throws IOException
execute a system process asynchronously. The method returns once the process starts executing.

Specified by:
executeCommandAsynchronously in interface Shell
Parameters:
pCommandString - the command string
Returns:
Process the process object for the caller to manage the lifetime of this process
Throws:
IOException

executeCommand

public int executeCommand(String pCommandString,
                          File pProcessRoot,
                          Properties pEnv)
                   throws InterruptedException,
                          IOException
execute a system process synchronously. The method returns when the process exits

Specified by:
executeCommand in interface Shell
Parameters:
pCommandString - the command string
pProcessRoot - the root directory where the process will be executed. Can be null if this parameter is not used
pEnv - the environment
Returns:
int the exit value of the system command
Throws:
InterruptedException - if the command is interrupted
IOException - if the command cannot be executed

executeCommand

public int executeCommand(String pCommandString,
                          File pProcessRoot,
                          Properties pEnv,
                          File pStdOut,
                          File pStdErr)
                   throws InterruptedException,
                          IOException
execute a command synchronously. The method returns when the process exits

Specified by:
executeCommand in interface Shell
Parameters:
pCommandString - the command string
pProcessRoot - the root directory where the process will be executed. Can be null if this parameter is not used
pStdOut - File to write the standard output to
pStdErr - File to write the standard error to
Returns:
int the exit value of the system command
Throws:
InterruptedException - if the command is interrupted
IOException - if the command cannot be executed

pipeStream

protected Thread pipeStream(InputStream pInputStream,
                            int pStream,
                            CommandListener pListener)
                     throws IOException
pipe the input of a stream to the output

Parameters:
pInputStream - input stream
pStream - the stream identifier STDOUT | STDERR
pListener - the listener to receive data
Throws:
IOException

executeCommand

public int executeCommand(String pCommandString,
                          File pProcessRoot,
                          Properties pEnv,
                          CommandListener pListener)
                   throws InterruptedException,
                          IOException
execute a command synchronously. The method returns when the process exits

Specified by:
executeCommand in interface Shell
Parameters:
pCommandString - the command string
pProcessRoot - the root directory where the process will be executed. Can be null if this parameter is not used
pListener - CommandListener that receives process output and error stream data
Returns:
int the exit value of the system command
Throws:
InterruptedException - if the command is interrupted
IOException - if the command cannot be executed