com.ibm.jtopenlite.command.program.workmgmt

Class OpenListOfJobs

  • java.lang.Object
    • com.ibm.jtopenlite.command.program.workmgmt.OpenListOfJobs
  • All Implemented Interfaces:
    Program, OpenListProgram<OpenListOfJobsFormat,OpenListOfJobsFormatListener>


    public class OpenListOfJobs
    extends java.lang.Object
    implements OpenListProgram<OpenListOfJobsFormat,OpenListOfJobsFormatListener>
    Use the QGYOLJOB API to access the list of job on the IBM i. This class fully implements the V5R4 specification of QGYOLJOB.

    Example:

     CommandConnection conn = CommandConnection.getConnection(...);
    
     OpenListOfJobsFormatOLJB0200 jobFormat = new OpenListOfJobsFormatOLJB0200(); // Use the OLJB0200 format to get key info back.
     int receiverSize = 100; // This should be large enough for the initial call.
     int numRecordsToReturn = 1; // Need to return at least one record to get the key definition back.
     int[] fieldsToReturn = new int[] { 1906 }; // Subsystem information.
    
     OpenListOfJobs jobList = new OpenListOfJobs(jobFormat, receiverSize, numRecordsToReturn, fieldsToReturn);
    
     OpenListOfJobsSelectionListener jobSelector = ...; // Define your own. Optional.
     jobList.setSelectionListener(jobSelector, OpenListOfJobs.SELECTION_OLJS0100);
    
     OpenListOfJobsSortListener jobSorter = ...; // Define your own. Optional.
     jobList.setSortListener(jobSorter);
    
     CommandResult result = conn.call(jobList);
     // Assuming it succeeded...
    
     OpenListOfJobsKeyField[] keyDefinitions = jobList.getKeyFields();
     ListInformation listInfo = jobList.getListInformation();
     byte[] requestHandle = listInfo.getRequestHandle();
     int recordLength = listInfo.getRecordLength();
    
     // Now, the list is building on the server.
     // Call GetListEntries once to wait for the list to finish building, for example.
     receiverSize = 100; // Should be good enough for the first call.
     numRecordsToReturn = 0;
     int startingRecord = -1; // Wait until whole list is built before returning. Optional.
     GetListEntries getJobs = new GetListEntries(receiverSize, requestHandle, recordLength, numRecordsToReturn, startingRecord, jobFormat);
     result = conn.call(getJobs);
     // Assuming it succeeded...
    
     listInfo = getJobs.getListInformation();
     int totalRecords = listInfo.getTotalRecords();
    
     // Now retrieve the job records in chunks of, for example, 300 at a time.
     numRecordsToReturn = 300;
     receiverSize = recordLength * numRecordsToReturn;
     startingRecord = 1;
     getJobs.setLengthOfReceiverVariable(receiverSize);
     getJobs.setNumberOfRecordsToReturn(numRecordsToReturn);
     getJobs.setStartingRecord(startingRecord);
     jobFormat.setKeyFields(keyDefinitions);
     OpenListOfJobsFormatOLJB0200Listener callback = ...; // Define your own.
     jobFormat.setListener(callback); // Ready to process.
    
     while (startingRecord <= totalRecords)
     {
       result = conn.call(getJobs);
       // Assuming it succeeded...
       listInfo = getJobs.getListInformation();
       startingRecord += listInfo.getRecordsReturned();
       getJobs.setStartingRecord(startingRecord);
     }
    
     // All done.
     CloseList close = new CloseList(requestHandle);
     result = conn.call(close);
     conn.close();