org.jppf.server.protocol
Class CommandLineTask

java.lang.Object
  extended by org.jppf.server.protocol.JPPFTask
      extended by org.jppf.server.protocol.CommandLineTask
All Implemented Interfaces:
Serializable, Runnable, EventListener, ProcessWrapperEventListener

public abstract class CommandLineTask
extends JPPFTask
implements ProcessWrapperEventListener

Instances of this class encapsulate the execution of an external process, program or shell script.
This task starts and external process using command line arguments, environment variables, and a list of input and/or output files to use or generated by the external process.
This task also captures the standard and error output (i.e. equivalent to System.out and System.err) of the external process.

Author:
Laurent Cohen
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jppf.server.protocol.JPPFTask
listeners
 
Constructor Summary
CommandLineTask()
          Default condtructor.
CommandLineTask(Map<String,String> env, String startDir, String... commands)
          Create an instance of this class and set the parameters of the external process or script to launch.
CommandLineTask(String... commands)
          Create an instance of this class and set the parameters of the external process or script to launch.
 
Method Summary
 void errorStreamAltered(ProcessWrapperEvent event)
          Notification that the process has written to its error stream.
 List<String> getCommandList()
          Get the list of command-line arguments.
 Map<String,String> getEnv()
          Get the environment variables to set.
 String getErrorOutput()
          Get the content of the error output for the process.
 String getStandardOutput()
          Get the content of the standard output for the process.
 String getStartDir()
          Get the directory to start the command in.
 boolean isCaptureOutput()
          Determines whether the process output is captured.
 void launchProcess()
          Run the external process or script.
 void outputStreamAltered(ProcessWrapperEvent event)
          Notification that the process has written to its output stream.
 void setCaptureOutput(boolean captureOutput)
          Specifies whether the process output is captured.
 void setCommandList(List<String> commandList)
          Set the list of command-line arguments.
 void setCommandList(String... commands)
          Set the list of command-line arguments.
 void setEnv(Map<String,String> env)
          Get the environment variables to set.
 void setStartDir(String startDir)
          Set the directory to start the command in.
 
Methods inherited from class org.jppf.server.protocol.JPPFTask
addJPPFTaskListener, fireNotification, getDataProvider, getException, getId, getListeners, getPosition, getResult, getTaskObject, getTimeout, getTimeoutDate, getTimeoutDateFormat, getTimeoutFormat, getTimeoutSchedule, onCancel, onRestart, onTimeout, removeJPPFTaskListener, setDataProvider, setException, setId, setPosition, setResult, setTimeout, setTimeoutDate, setTimeoutDate, setTimeoutSchedule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Constructor Detail

CommandLineTask

public CommandLineTask()
Default condtructor.


CommandLineTask

public CommandLineTask(String... commands)
Create an instance of this class and set the parameters of the external process or script to launch.

Parameters:
commands - the list of command-line arguments.

CommandLineTask

public CommandLineTask(Map<String,String> env,
                       String startDir,
                       String... commands)
Create an instance of this class and set the parameters of the external process or script to launch.

Parameters:
env - the environment variables to set.
startDir - the directory to start the command in.
commands - the list of command-line arguments.
Method Detail

launchProcess

public void launchProcess()
                   throws Exception
Run the external process or script.

Throws:
Exception - if an error occurs.

isCaptureOutput

public boolean isCaptureOutput()
Determines whether the process output is captured.

Returns:
true if the output is cpatured, false otherwise.

setCaptureOutput

public void setCaptureOutput(boolean captureOutput)
Specifies whether the process output is captured.

Parameters:
captureOutput - true if the output is cpatured, false otherwise.

getStandardOutput

public String getStandardOutput()
Get the content of the standard output for the process.

Returns:
the output as a string.

getErrorOutput

public String getErrorOutput()
Get the content of the error output for the process.

Returns:
the output as a string.

getCommandList

public List<String> getCommandList()
Get the list of command-line arguments.

Returns:
a list of arguments as strings.

setCommandList

public void setCommandList(List<String> commandList)
Set the list of command-line arguments.

Parameters:
commandList - a list of arguments as strings.

setCommandList

public void setCommandList(String... commands)
Set the list of command-line arguments.

Parameters:
commands - a list of arguments as strings.

getEnv

public Map<String,String> getEnv()
Get the environment variables to set.

Returns:
a map of variable names to their corresponding values.

setEnv

public void setEnv(Map<String,String> env)
Get the environment variables to set.

Parameters:
env - a map of variable names to their corresponding values.

getStartDir

public String getStartDir()
Get the directory to start the command in.

Returns:
the start directory as a string.

setStartDir

public void setStartDir(String startDir)
Set the directory to start the command in.

Parameters:
startDir - the start directory as a string.

outputStreamAltered

public void outputStreamAltered(ProcessWrapperEvent event)
Notification that the process has written to its output stream.

Specified by:
outputStreamAltered in interface ProcessWrapperEventListener
Parameters:
event - encapsulates the output stream's content.
See Also:
ProcessWrapperEventListener.outputStreamAltered(org.jppf.process.event.ProcessWrapperEvent)

errorStreamAltered

public void errorStreamAltered(ProcessWrapperEvent event)
Notification that the process has written to its error stream.

Specified by:
errorStreamAltered in interface ProcessWrapperEventListener
Parameters:
event - encapsulate the error stream's content.
See Also:
ProcessWrapperEventListener.errorStreamAltered(org.jppf.process.event.ProcessWrapperEvent)


Copyright © 2005-2010 JPPF Team.