edu.rit.pj.job
Class Job
- java.lang.Object
-
- edu.rit.pj.job.Job
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable, java.lang.Runnable
public class Job extends java.lang.Object implements java.lang.Runnable, java.io.ExternalizableClass Job encapsulates a job and its attributes. A job is typically created by a JobGenerator. The job's attributes are:- Job number. A JobGenerator assigns a unique job number to each job it creates.
- Description. An arbitrary string. The Runner program prints the job number and description whenever a job is started.
- Fully-qualified name of the main program class. To run a job, the main program class's public static void main(String[]) method is called.
- List of argument strings for the main() method.
- Standard input redirection. The standard input may be redirected from a file. The job redirects the per-thread standard input stream in class Stdio. For redirection to work, the main() method must use Stdio.in() for the standard input.
- Standard output redirection. The standard output may be redirected to a file, either overwriting or appending to the file. The job redirects the per-thread standard output stream in class Stdio. For redirection to work, the main() method must use Stdio.out() for the standard output.
- Standard error redirection. The standard error may be redirected to a file, either overwriting or appending to the file. The standard error may also be redirected to the same place as the standard output. The job redirects the per-thread standard error stream in class Stdio. For redirection to work, the main() method must use Stdio.err() for the standard error.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Job()Construct a new uninitialized job.Job(int theJobNumber, java.lang.String theDescription, java.lang.String theMainClassName)Construct a new job.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddArgument(java.lang.String arg)Add the given argument string to this job.java.lang.StringgetDescription()Returns this job's description.intgetJobNumber()Returns this job's number.voidreadExternal(java.io.ObjectInput in)Read this job from the given object input stream.voidrun()Run this job.voidstderrAppendToFile(java.io.File file)Append this job's standard error to the end of the given file.voidstderrToFile(java.io.File file)Store this job's standard error in the given file.voidstderrToStdout()Redirect this job's standard error to the same place as this job's standard output.voidstdinFromFile(java.io.File file)Read this job's standard input from the given file.voidstdoutAppendToFile(java.io.File file)Append this job's standard output to the end of the given file.voidstdoutToFile(java.io.File file)Store this job's standard output in the given file.voidwriteExternal(java.io.ObjectOutput out)Write this job to the given object output stream.
-
-
-
Constructor Detail
-
Job
public Job()
Construct a new uninitialized job. This constructor is for use only by object deserialization.
-
Job
public Job(int theJobNumber, java.lang.String theDescription, java.lang.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:
java.lang.NullPointerException- (unchecked exception) Thrown if theMainClassName is null.
-
-
Method Detail
-
getJobNumber
public int getJobNumber()
Returns this job's number.- Returns:
- Job number.
-
getDescription
public java.lang.String getDescription()
Returns this job's description.- Returns:
- Job description.
-
addArgument
public void addArgument(java.lang.String arg)
Add the given argument string to this job.- Parameters:
arg- Argument string.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if arg is null.
-
stdinFromFile
public void stdinFromFile(java.io.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:
java.lang.NullPointerException- (unchecked exception) Thrown if file is null.
-
stdoutToFile
public void stdoutToFile(java.io.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:
java.lang.NullPointerException- (unchecked exception) Thrown if file is null.
-
stdoutAppendToFile
public void stdoutAppendToFile(java.io.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:
java.lang.NullPointerException- (unchecked exception) Thrown if file is null.
-
stderrToFile
public void stderrToFile(java.io.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:
java.lang.NullPointerException- (unchecked exception) Thrown if file is null.
-
stderrAppendToFile
public void stderrAppendToFile(java.io.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:
java.lang.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.- The per-thread standard input, standard output, and standard error in class Stdio are redirected as necessary.
- This job's main class is found, using the calling thread's context class loader.
- The main class's public static void main(String[]) method is found.
- 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:
runin interfacejava.lang.Runnable
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this job to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this job from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if an object's class could not be found.
-
-
DMelt 3.0 © DataMelt by jWork.ORG