Package edu.rit.pj.job
Class Job
java.lang.Object
edu.rit.pj.job.Job
- All Implemented Interfaces:
Externalizable
,Serializable
,Runnable
Class 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 useStdio.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 useStdio.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 useStdio.err()
for the standard error.
- Version:
- 09-Oct-2010
- Author:
- Alan Kaminsky
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addArgument
(String arg) Add the given argument string to this job.Returns this job's description.int
Returns this job's number.void
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
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
Write this job to the given object output stream.
-
Constructor Details
-
Job
public Job()Construct a new uninitialized job. This constructor is for use only by object deserialization. -
Job
Construct a new job. The job has the given job number and description. The job will run thepublic 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 iftheMainClassName
is null.
-
-
Method Details
-
getJobNumber
public int getJobNumber()Returns this job's number.- Returns:
- Job number.
-
getDescription
Returns this job's description.- Returns:
- Job description.
-
addArgument
Add the given argument string to this job.- Parameters:
arg
- Argument string.- Throws:
NullPointerException
- (unchecked exception) Thrown ifarg
is null.
-
stdinFromFile
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 iffile
is null.
-
stdoutToFile
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 iffile
is null.
-
stdoutAppendToFile
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 iffile
is null.
-
stderrToFile
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 iffile
is null.
-
stderrAppendToFile
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 iffile
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.
-
writeExternal
Write this job to the given object output stream.- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
- Thrown if an I/O error occurred.
-
readExternal
Read this job from the given object input stream.- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
- Thrown if an I/O error occurred.ClassNotFoundException
- Thrown if an object's class could not be found.
-