edu.rit.pj.job
Class Job

java.lang.Object
  extended by edu.rit.pj.job.Job
All Implemented Interfaces:
Externalizable, Serializable, Runnable

public class Job
extends Object
implements Runnable, Externalizable

Class Job encapsulates a job and its attributes. A job is typically created by a JobGenerator. The job's attributes are:

See Also:
Serialized Form

Constructor Summary
Job()
          Construct a new uninitialized job.
Job(int theJobNumber, String theDescription, String theMainClassName)
          Construct a new job.
 
Method Summary
 void addArgument(String arg)
          Add the given argument string to this job.
 String getDescription()
          Returns this job's description.
 int getJobNumber()
          Returns this job's number.
 void readExternal(ObjectInput in)
          Read this job from the given object input stream.
 void run()
          Run this job.
 void stderrAppendToFile(File file)
          Append this job's standard error to the end of the given file.
 void stderrToFile(File file)
          Store this job's standard error in the given file.
 void stderrToStdout()
          Redirect this job's standard error to the same place as this job's standard output.
 void stdinFromFile(File file)
          Read this job's standard input from the given file.
 void stdoutAppendToFile(File file)
          Append this job's standard output to the end of the given file.
 void stdoutToFile(File file)
          Store this job's standard output in the given file.
 void writeExternal(ObjectOutput out)
          Write this job to the given object output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Job

public Job()
Construct a new uninitialized job. This constructor is for use only by object deserialization.


Job

public Job(int theJobNumber,
           String theDescription,
           String theMainClassName)
Construct a new job. The job has the given job number and description. The job will run the public static void main(String[]) method in the given class.

Parameters:
theJobNumber - Job number.
theDescription - Job description.
theMainClassName - Fully qualified name of main class.
Throws:
NullPointerException - (unchecked exception) Thrown if theMainClassName is null.
Method Detail

getJobNumber

public int getJobNumber()
Returns this job's number.

Returns:
Job number.

getDescription

public String getDescription()
Returns this job's description.

Returns:
Job description.

addArgument

public void addArgument(String arg)
Add the given argument string to this job.

Parameters:
arg - Argument string.
Throws:
NullPointerException - (unchecked exception) Thrown if arg is null.

stdinFromFile

public void stdinFromFile(File file)
Read this job's standard input from the given file. It is an error if the file does not exist.

Parameters:
file - File.
Throws:
NullPointerException - (unchecked exception) Thrown if file is null.

stdoutToFile

public void stdoutToFile(File file)
Store this job's standard output in the given file. The file is created if it does not exist. The file is overwritten if it does exist.

Parameters:
file - File.
Throws:
NullPointerException - (unchecked exception) Thrown if file is null.

stdoutAppendToFile

public void stdoutAppendToFile(File file)
Append this job's standard output to the end of the given file. The file is created if it does not exist.

Parameters:
file - File.
Throws:
NullPointerException - (unchecked exception) Thrown if file is null.

stderrToFile

public void stderrToFile(File file)
Store this job's standard error in the given file. The file is created if it does not exist. The file is overwritten if it does exist.

Parameters:
file - File.
Throws:
NullPointerException - (unchecked exception) Thrown if file is null.

stderrAppendToFile

public void stderrAppendToFile(File file)
Append this job's standard error to the end of the given file. The file is created if it does not exist.

Parameters:
file - File.
Throws:
NullPointerException - (unchecked exception) Thrown if file is null.

stderrToStdout

public void stderrToStdout()
Redirect this job's standard error to the same place as this job's standard output.


run

public void run()
Run this job.

  1. The per-thread standard input, standard output, and standard error in class Stdio are redirected as necessary.

  2. This job's main class is found, using the calling thread's context class loader.

  3. The main class's public static void main(String[]) method is found.

  4. The main() method is called, passing in this job's arguments.

If an I/O error occurs during Step 1, a RuntimeException wrapping an IOException is thrown. If any exception is thrown during Steps 2 through 4, an exception stack trace is printed on the per-thread standard error (which may have been redirected), but the exception is not propagated.

Specified by:
run in interface Runnable

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Write this job to the given object output stream.

Specified by:
writeExternal in interface Externalizable
Parameters:
out - Object output stream.
Throws:
IOException - Thrown if an I/O error occurred.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Read this job from the given object input stream.

Specified by:
readExternal in interface Externalizable
Parameters:
in - Object input stream.
Throws:
IOException - Thrown if an I/O error occurred.
ClassNotFoundException - Thrown if an object's class could not be found.


Copyright © 2005-2012 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.