org.ourgrid.common.executor
Class LinuxExecutor

java.lang.Object
  extended by org.ourgrid.common.executor.AbstractExecutor
      extended by org.ourgrid.common.executor.LinuxExecutor
All Implemented Interfaces:
java.io.Serializable, Executor

public class LinuxExecutor
extends AbstractExecutor

This class is the concrete implementation of Executor interface that provides the platform dependent command execution. The reationale behind this implementation is to implement Linux native command invocation.

See Also:
Serialized Form

Constructor Summary
protected LinuxExecutor()
          A protected constructor to be accessible only by the ExecutorFactory.
 
Method Summary
 void chmod(java.io.File file, java.lang.String modeStr)
          Changes the permissions for the indicated file.
protected  java.io.File createScript(java.lang.String command, java.lang.String dirName, java.util.Map envVars, ExecutorHandle handle)
          Creates a script file to execute the command passed as paramether.
 ExecutorHandle execute(java.lang.String dirName, java.lang.String command)
          This method implements the command execution feature for Linux environment.
 ExecutorHandle execute(java.lang.String dirName, java.lang.String command, java.util.Map envVars)
          This method implements the command execution feature for Linux environment.
protected  ExecutorHandle getNextHandle()
          This method manage the handles issued for each command execution
 ExecutorResult getResult(ExecutorHandle handle)
          Blocks until the command finishes and returns its result
protected  void includeInProcesses(ExecutorHandle handle, java.lang.Process process, java.lang.String dirName)
          Adds a process into the set of the ones which results were not collected yet.
 void kill(ExecutorHandle handle)
          Kills command that was issued via an execute method
 
Methods inherited from class org.ourgrid.common.executor.AbstractExecutor
catchOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinuxExecutor

protected LinuxExecutor()
A protected constructor to be accessible only by the ExecutorFactory.

Method Detail

getNextHandle

protected ExecutorHandle getNextHandle()
This method manage the handles issued for each command execution

Returns:
A handle to be used by the client to identify its execution

chmod

public void chmod(java.io.File file,
                  java.lang.String modeStr)
           throws ExecutorException
Description copied from interface: Executor
Changes the permissions for the indicated file. Permissions are described using the "rwx" Linux convention. The permissions are changed in a way that further access from this JVM will see the new permissions.

Parameters:
file - the File object
modeStr - the new permission in "rwx" format
Throws:
ExecutorException - error changing the permissions
See Also:
Executor.chmod(File, String)

execute

public ExecutorHandle execute(java.lang.String dirName,
                              java.lang.String command)
                       throws ExecutorException
This method implements the command execution feature for Linux environment.

Parameters:
command - The command must be executed
dirName - The execution root directory following the Linux name convention
Returns:
A handle that identifies this execution
Throws:
ExecutorException - If the command could not be executed.

execute

public ExecutorHandle execute(java.lang.String dirName,
                              java.lang.String command,
                              java.util.Map envVars)
                       throws ExecutorException
This method implements the command execution feature for Linux environment.

Parameters:
command - The command must be executed
dirName - The execution root directory following the Linux name convention
envVars - A map (var name, value) with the environment variables used by the command
Returns:
A handle that identifies this execution
Throws:
ExecutorException - If the command could not be executed.

includeInProcesses

protected void includeInProcesses(ExecutorHandle handle,
                                  java.lang.Process process,
                                  java.lang.String dirName)
Adds a process into the set of the ones which results were not collected yet.

Parameters:
handle - The handle for the process
process - The process to be included at the group
dirName - The directory where the process was started.

createScript

protected java.io.File createScript(java.lang.String command,
                                    java.lang.String dirName,
                                    java.util.Map envVars,
                                    ExecutorHandle handle)
                             throws ExecutorException
Creates a script file to execute the command passed as paramether. This script will execute the command into the directory and will export the environment variables at the map passed as arguments.

Parameters:
command - The command to be executed.
dirName - Where the command has to be executed.
envVars - The environment variables to be exported and used by the command.
handle - The process handle.
Returns:
A script file that has the functionalities described here.
Throws:
ExecutorException - If the directory passed is not valid (does not exists) and if could not create the script file for any I/O problem..

kill

public void kill(ExecutorHandle handle)
          throws ExecutorException
Description copied from interface: Executor
Kills command that was issued via an execute method

Parameters:
handle - the command handle
Throws:
ExecutorException - when there is a problem while changing .the permissions of a file.
See Also:
Executor.kill(ExecutorHandle)

getResult

public ExecutorResult getResult(ExecutorHandle handle)
                         throws ExecutorException
Description copied from interface: Executor
Blocks until the command finishes and returns its result

Parameters:
handle - the command handle
Returns:
ExecutorResult StdOut, StdErr and exitValue from kill command.
Throws:
ExecutorException - when there is a problem while obtaining the result of an execution.
See Also:
Executor.getResult(ExecutorHandle)