com.ibm.jzos.sample
Class MvsJobSubmitter

java.lang.Object
  extended by com.ibm.jzos.sample.MvsJobSubmitter

public class MvsJobSubmitter
extends java.lang.Object

Sample program which submits a job to the internal reader, returning a MvsJob object containing the jobname and jobid.

The class relies on sample Rexx scripts spawned as a child process via the Exec class.

The JZOS ZFile class can be used to submit JCL if you use ZFile.bpxwdyn(String) to allocate a DD to "SYSOUT(A) WRITER(INTRDR)", but this mechanism does not have the ability to return the submitted job id (JOBnnnnn). Fortunately, the Rexx "submit()" function has the ability to submit JCL and get the jobid back, so this example shows how to attach a sample USS Rexx script ("submitJob") as a child process and send it JCL on its stdin handle.

In order for JZOS to find the sample REXX script, the System property jzos.script.path must be set to point to the sample scripts directory. See the Installation Guide for details.

Similarly, getting status for an executing job requires an APF authorized program interface to the subsystem api. The TSO "STATUS" command can be executed via the Rexx "TSO" command processor to obtain this information. See the sample "jobStatus" Rexx script.


Field Summary
static java.lang.String JOB_STATUS_CMD
           
static long ONE_MINUTE
           
static long ONE_SECOND
           
static java.lang.String SUBMIT_JOB_CMD
           
static long TWO_SECONDS
           
 
Constructor Summary
MvsJobSubmitter()
          Construct an instance, which causes the "submitJob" Rexx script to be started to receive our JCL.
 
Method Summary
protected static void copyFile(java.lang.String filename, java.io.Writer writer)
          Copy a file given its name to a Writer.
protected  void executeSubmit()
          Start the "submitJob" child process.
protected static java.lang.String[] getEnvironment()
           
 java.io.Writer getInternalReaderWriter()
          Answers a writer that can be used by the client to send JCL to the Rexx submitJob process.
static java.lang.String getJobStatus(MvsJob job)
          Returns the status for a job using the TSO "status" command, which is invoked via the "jobStatus" REXX USS script.
protected static java.lang.String getStatusCommand(MvsJob job)
           
protected static java.lang.String getSubmitCommand()
           
static void main(java.lang.String[] args)
          A sample main method that submits JCL read from a file and then polls its status (for up to a minute) until it is complete.
 MvsJob submitJob()
          Answers an MvsJob object which is a simple bean holding the submitted jobname and userid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_SECOND

public static final long ONE_SECOND
See Also:
Constant Field Values

TWO_SECONDS

public static final long TWO_SECONDS
See Also:
Constant Field Values

ONE_MINUTE

public static final long ONE_MINUTE
See Also:
Constant Field Values

SUBMIT_JOB_CMD

public static final java.lang.String SUBMIT_JOB_CMD
See Also:
Constant Field Values

JOB_STATUS_CMD

public static final java.lang.String JOB_STATUS_CMD
See Also:
Constant Field Values
Constructor Detail

MvsJobSubmitter

public MvsJobSubmitter()
                throws java.io.IOException
Construct an instance, which causes the "submitJob" Rexx script to be started to receive our JCL.

Throws:
java.io.IOException
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
A sample main method that submits JCL read from a file and then polls its status (for up to a minute) until it is complete.

The first argument to main can be a Unix file/path name or a "//dataset.name". The name is given directory to the FileFactory.newBufferedReader(String) method to open the JCL file to submit.

Throws:
java.io.IOException

getInternalReaderWriter

public java.io.Writer getInternalReaderWriter()
                                       throws java.io.IOException
Answers a writer that can be used by the client to send JCL to the Rexx submitJob process. Clients should either flush() or close() this Writer to ensure that buffered data is actually sent to the child process

Returns:
Writer
Throws:
java.io.IOException

submitJob

public MvsJob submitJob()
                 throws java.io.IOException
Answers an MvsJob object which is a simple bean holding the submitted jobname and userid. The method should be called once after writing jcl to getInternalReaderWriter() and closing the writer.

Returns:
MvsJob if submitted successfully, otherwise an exception is thrown
Throws:
java.io.IOException - if there is an error communicating with the child Rexx process or if the child process had an error submitting the process.

getJobStatus

public static java.lang.String getJobStatus(MvsJob job)
                                     throws java.io.IOException
Returns the status for a job using the TSO "status" command, which is invoked via the "jobStatus" REXX USS script.

Returns:
String the TSO "STATUS" command status
Throws:
java.io.IOException - if there was an error communicating with the child REXX script process

executeSubmit

protected void executeSubmit()
                      throws java.io.IOException
Start the "submitJob" child process.

Throws:
java.io.IOException

getSubmitCommand

protected static java.lang.String getSubmitCommand()

getStatusCommand

protected static java.lang.String getStatusCommand(MvsJob job)

getEnvironment

protected static java.lang.String[] getEnvironment()

copyFile

protected static void copyFile(java.lang.String filename,
                               java.io.Writer writer)
                        throws java.io.IOException
Copy a file given its name to a Writer. After copying or on error, close both files.

Throws:
java.io.IOException