it.sauronsoftware.cron4j
Class ProcessTask

java.lang.Object
  extended by it.sauronsoftware.cron4j.Task
      extended by it.sauronsoftware.cron4j.ProcessTask

public class ProcessTask
extends Task

A built-in Task implementation which can be used to run an external process.

Since:
2.1
Author:
Carlo Pelliccia

Constructor Summary
ProcessTask(java.lang.String command)
          Creates the task.
ProcessTask(java.lang.String[] command)
          Creates the task.
ProcessTask(java.lang.String[] command, java.lang.String[] envs)
          Creates the task.
ProcessTask(java.lang.String[] command, java.lang.String[] envs, java.io.File directory)
          Creates the task.
 
Method Summary
 boolean canBeStopped()
          Returns true.
 void execute(TaskExecutionContext context)
          Implements Task.execute(TaskExecutionContext).
 java.lang.String[] getCommand()
          Returns the command executed by this task.
 java.io.File getDirectory()
          Resturns the working directory for the spawned process.
 java.lang.String[] getEnvs()
          Returns the environment variables, in the name=value form, used by the task to run its process.
 java.io.File getStderrFile()
          Returns the standard error file (optional).
 java.io.File getStdinFile()
          Returns the standard input file (optional).
 java.io.File getStdoutFile()
          Returns the standard output file (optional).
 void setCommand(java.lang.String[] command)
          Sets the command executed by this task.
 void setDirectory(java.io.File directory)
          Sets the working directory for the spawned process.
 void setEnvs(java.lang.String[] envs)
          Sets the environment variables, in the name=value form, used by the task to run its process.
 void setStderrFile(java.io.File stderrFile)
          Sets the standard error file (optional).
 void setStdinFile(java.io.File stdinFile)
          Sets the standard input file (optional).
 void setStdoutFile(java.io.File stdoutFile)
          Sets the standard output file (optional).
 java.lang.String toString()
          Overrides Object.toString().
 
Methods inherited from class it.sauronsoftware.cron4j.Task
canBePaused, supportsCompletenessTracking, supportsStatusTracking
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProcessTask

public ProcessTask(java.lang.String[] command,
                   java.lang.String[] envs,
                   java.io.File directory)
Creates the task.

Parameters:
command - The command to launch and its arguments.
envs - Environment variables for the spawned process, in the form name=value. If null the process will inherit the current JVM environment variables.
directory - Working directory for the spawned process. If null the process will inherit the current JVM working directory.

ProcessTask

public ProcessTask(java.lang.String[] command,
                   java.lang.String[] envs)
Creates the task.

Parameters:
command - The command to launch and its arguments.
envs - Environment variables for the spawned process, in the form name=value. If null the process will inherit the current JVM environment variables.

ProcessTask

public ProcessTask(java.lang.String[] command)
Creates the task.

Parameters:
command - The command to launch and its arguments.

ProcessTask

public ProcessTask(java.lang.String command)
Creates the task.

Parameters:
command - The command to launch.
Method Detail

canBeStopped

public boolean canBeStopped()
Returns true.

Overrides:
canBeStopped in class Task
Returns:
true if this task can be stopped; false otherwise.

getCommand

public java.lang.String[] getCommand()
Returns the command executed by this task.

Returns:
The command executed by this task.

setCommand

public void setCommand(java.lang.String[] command)
Sets the command executed by this task.

Parameters:
command - The command executed by this task.

getEnvs

public java.lang.String[] getEnvs()
Returns the environment variables, in the name=value form, used by the task to run its process. If null the process will inherit the current JVM environment variables.

Returns:
The environment variables, in the name=value form, used by the task to run its process. If null the process will inherit the current JVM environment variables.

setEnvs

public void setEnvs(java.lang.String[] envs)
Sets the environment variables, in the name=value form, used by the task to run its process. If null the process will inherit the current JVM environment variables.

Parameters:
envs - The environment variables, in the name=value form, used by the task to run its process. If null the process will inherit the current JVM environment variables.

getDirectory

public java.io.File getDirectory()
Resturns the working directory for the spawned process. If null the process will inherit the current JVM working directory.

Returns:
The working directory for the spawned process. If null the process will inherit the current JVM working directory.

setDirectory

public void setDirectory(java.io.File directory)
Sets the working directory for the spawned process. If null the process will inherit the current JVM working directory.

Parameters:
directory - The working directory for the spawned process. If null the process will inherit the current JVM working directory.

getStdinFile

public java.io.File getStdinFile()
Returns the standard input file (optional). If supplied, the standard input channel of the spawned process will be read from the given file.

Returns:
The standard input file (optional).

setStdinFile

public void setStdinFile(java.io.File stdinFile)
Sets the standard input file (optional). If supplied, the standard input channel of the spawned process will be read from the given file.

Parameters:
stdinFile - The standard input file (optional).

setStdoutFile

public void setStdoutFile(java.io.File stdoutFile)
Sets the standard output file (optional). If supplied, the standard output channel of the spawned process will be written in the given file.

Parameters:
stdoutFile - The standard output file (optional).

getStdoutFile

public java.io.File getStdoutFile()
Returns the standard output file (optional). If supplied, the standard output channel of the spawned process will be written in the given file.

Returns:
The standard output file (optional).

setStderrFile

public void setStderrFile(java.io.File stderrFile)
Sets the standard error file (optional). If supplied, the standard error channel of the spawned process will be written in the given file.

Parameters:
stderrFile - The standard error file (optional).

getStderrFile

public java.io.File getStderrFile()
Returns the standard error file (optional). If supplied, the standard error channel of the spawned process will be written in the given file.

Returns:
The standard error file (optional).

execute

public void execute(TaskExecutionContext context)
             throws java.lang.RuntimeException
Implements Task.execute(TaskExecutionContext). Runs the given command as a separate process and waits for its end.

Specified by:
execute in class Task
Parameters:
context - The execution context.
Throws:
java.lang.RuntimeException - Task execution has somehow failed.

toString

public java.lang.String toString()
Overrides Object.toString().

Overrides:
toString in class java.lang.Object