midrange.com code scratchpad
Name:
SubsystemJobOpenList.Java, SubsystemJobListItem.java, SubsystemJobOpenListTest.java
Scriptlanguage:
Java
Tabwidth:
4
Date:
07/02/2015 08:01:33 am
IP:
Logged
Description:
Get AS400 Subsystem job with Open List of Jobs (QGYOLJOB) API format OLJB0300 and return SubsystemJobListItem or subsystem jobs []
Code:
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Filename: SubsystemJobOpenList.java
  5. //
  6. // Author  : Vengoal Chang
  7. // 
  8. // Date    : 2015/07/01
  9. //
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. package com.vengoal.as400.list;
  13.  
  14. import java.io.IOException;
  15. import java.util.TreeMap;
  16.  
  17. import com.ibm.as400.access.AS400;
  18. import com.ibm.as400.access.AS400Exception;
  19. import com.ibm.as400.access.AS400SecurityException;
  20. import com.ibm.as400.access.AS400Text;
  21. import com.ibm.as400.access.BinaryConverter;
  22. import com.ibm.as400.access.CharConverter;
  23. import com.ibm.as400.access.ErrorCodeParameter;
  24. import com.ibm.as400.access.ErrorCompletingRequestException;
  25. import com.ibm.as400.access.Job;
  26. import com.ibm.as400.access.ObjectDoesNotExistException;
  27. import com.ibm.as400.access.ProgramCall;
  28. import com.ibm.as400.access.ProgramParameter;
  29. import com.ibm.as400.access.Trace;
  30. import com.ibm.as400.access.list.OpenList;
  31.  
  32. /**
  33.  * Represents a list of subsystem jobs on the system with Open List of Jobs (QGYOLJOB) API. 
  34.  * By default, following keys retrieved:
  35.  *             keys_[0] = 305;
  36.  *            keys_[1] = 601;
  37.  *            keys_[2] = 602;
  38.  *            keys_[3] = 1307;
  39.  *            keys_[4] = 1308;
  40.  *            keys_[5] = 1309;
  41.  *            keys_[6] = 1906;
  42.  * 
  43.  * List of Keys Supported for Format OLJB0300 reference:
  44.  * http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/apis/qgyoljob.htm?lang=en
  45.  *
  46.  */
  47. public class SubsystemJobOpenList extends OpenList {
  48.         
  49.     private String subsystem_;
  50.     private Job[] subsystemJobs_;
  51.     
  52.     // Sort keys.
  53.     private int currentSortKey_ = 1;
  54.         
  55.     // Info saved between calls to load() and getJobs().
  56.     private int numKeysReturned_;
  57.     private int[] keyFieldsReturned_;
  58.     private char[] keyTypesReturned_;
  59.     private int[] keyLengthsReturned_;
  60.     private int[] keyOffsetsReturned_;
  61.         
  62.     // Keys to pre-load.
  63.     private int currentKey_ = 7;
  64.     private int[] keys_ = new int[currentKey_];
  65.     
  66.     public SubsystemJobOpenList(AS400 system, String subsystem) {
  67.          super(system);
  68.          this.subsystem_ = subsystem;
  69.             // Figure out Job information default return key fields
  70.             keys_[0] = 305;
  71.             keys_[1] = 601;
  72.             keys_[2] = 602;
  73.             keys_[3] = 1307;
  74.             keys_[4] = 1308;
  75.             keys_[5] = 1309;
  76.             keys_[6] = 1906;        
  77.     }
  78.     
  79.     public void addJobAttributeToRetrieve(int attribute){
  80.         if (currentKey_ >= keys_.length){
  81.             // Resize.
  82.             int[] temp = keys_;
  83.             keys_ = new int[temp.length * 2];
  84.             System.arraycopy(temp, 0, keys_, 0, temp.length);
  85.         }
  86.         keys_[currentKey_++] = attribute;
  87.     }
  88.     
  89.     public Job[] getSubsystemJobs(){
  90.         return subsystemJobs_;
  91.     }
  92.  
  93.     @Override
  94.     protected byte[] callOpenListAPI() throws AS400SecurityException,
  95.             ErrorCompletingRequestException, InterruptedException, IOException,
  96.             ObjectDoesNotExistException {
  97.         if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Opening spooled file list.");
  98.  
  99.         int lengthOfReceiverVariableDefinitionInformation = 4 + 20 * currentKey_;
  100.         byte[] keyOfFieldsToBeReturned = new byte[4 * currentKey_];
  101.         for (int i = 0; i < currentKey_; ++i)
  102.         {
  103.             BinaryConverter.intToByteArray(keys_[i], keyOfFieldsToBeReturned, i * 4);
  104.         }
  105.         
  106.         // Figure out our sort information
  107.         byte[] sortInformation = new byte[4 + currentSortKey_ * 12];
  108.         BinaryConverter.intToByteArray(currentSortKey_, sortInformation, 0);
  109.         int fieldStartingPosition = 1;
  110.         int fieldLength = 10;
  111.         short dataType = (short)4;
  112.         BinaryConverter.intToByteArray(fieldStartingPosition, sortInformation, 4 );
  113.         BinaryConverter.intToByteArray(fieldLength, sortInformation, 8);
  114.         BinaryConverter.shortToByteArray(dataType, sortInformation, 12);
  115.         // Sort order 0xF1 = ascending, 0xF2 = descending.
  116.         sortInformation[14] = (byte)0xF1;
  117.         
  118.         // Figure out our selection criteria.
  119.         byte[] jobSelectionInformation = new byte[206];
  120.         
  121.         // Generate text objects based on system CCSID.
  122.         CharConverter conv = new CharConverter(system_.getCcsid(), system_);
  123.         
  124.         for (int i = 0; i < 26; ++i) jobSelectionInformation[i] = 0x40;
  125.         String selectionJobName_ = "*ALL";
  126.         String selectionUserName_= "*ALL";
  127.         String selectionJobNumber_= "*ALL";
  128.         String selectionJobType_= "*";
  129.         conv.stringToByteArray(selectionJobName_.toUpperCase(), jobSelectionInformation, 0);
  130.         conv.stringToByteArray(selectionUserName_.toUpperCase(), jobSelectionInformation, 10);
  131.         conv.stringToByteArray(selectionJobNumber_, jobSelectionInformation, 20);
  132.         conv.stringToByteArray(selectionJobType_, jobSelectionInformation, 26);
  133.         
  134.         int offset = 195;
  135.         int numberOfSubsystem = 1;
  136.  
  137.         BinaryConverter.intToByteArray(offset, jobSelectionInformation, 76);
  138.         BinaryConverter.intToByteArray(numberOfSubsystem, jobSelectionInformation, 80);
  139.         // Subsystem name
  140.         AS400Text subsystemText = new AS400Text(10, system_);
  141.         byte[] subSystemBytes = subsystemText.toBytes(subsystem_);            
  142.         System.arraycopy(subSystemBytes, 0, jobSelectionInformation, offset, 10);
  143.         offset += 10;             
  144.         
  145.         // Setup program parameters.
  146.         ProgramParameter[] parameters = new ProgramParameter[]
  147.         {
  148.             // Receiver variable, output, char(*).
  149.             new ProgramParameter(0),
  150.             // Length of receiver variable, input, binary(4).
  151.             new ProgramParameter(new byte[] { 0x00, 0x00, 0x00, 0x00 } ),
  152.             // Format name, input, char(8), EBCDIC 'OLJB0300'.
  153.             new ProgramParameter(new byte[] { (byte)0xD6, (byte)0xD3, (byte)0xD1, (byte)0xC2, (byte)0xF0, (byte)0xF3, (byte)0xF0, (byte)0xF0 } ),
  154.             // Receiver variable definition information, output, char(*).
  155.             new ProgramParameter(lengthOfReceiverVariableDefinitionInformation),
  156.             // Length of receiver variable definition information, input, binary(4).
  157.             new ProgramParameter(BinaryConverter.intToByteArray(lengthOfReceiverVariableDefinitionInformation)),
  158.             // List information, output, char(80).
  159.             new ProgramParameter(80),
  160.             // Number of records to return, input, binary(4).
  161.             // Special value '-1' indicates that "all records are built synchronously in the list".
  162.             new ProgramParameter(new byte[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF } ),
  163.             // Sort information, input, char(*).
  164.             new ProgramParameter(sortInformation),
  165.             // Job selection information, input, char(*).
  166.             new ProgramParameter(jobSelectionInformation),
  167.             // Size of job selection information, input, binary(4).
  168.             new ProgramParameter(BinaryConverter.intToByteArray(jobSelectionInformation.length)),
  169.             // Number of fields to return, input, binary(4).
  170.             new ProgramParameter(BinaryConverter.intToByteArray(currentKey_)),
  171.             // Key of fields to be returned, input, array(*) of binary(4).
  172.             new ProgramParameter(keyOfFieldsToBeReturned),
  173.             // Error code, I/0, char(*).
  174.             new ErrorCodeParameter(),
  175.             // Job selection format name, input, char(8), EBCDIC 'OLJS0200'.
  176.             new ProgramParameter(new byte[] { (byte)0xD6, (byte)0xD3, (byte)0xD1, (byte)0xE2, (byte)0xF0, (byte)0xF2, (byte)0xF0, (byte)0xF0 } )
  177.         };
  178.         
  179.         // Call the program.
  180.         ProgramCall pc = new ProgramCall(system_, "/QSYS.LIB/QGY.LIB/QGYOLJOB.PGM", parameters);
  181.         
  182.         if (!pc.run())
  183.         {
  184.             throw new AS400Exception(pc.getMessageList());
  185.         }
  186.         
  187.         // Key information returned.
  188.         byte[] defInfo = parameters[3].getOutputData();
  189.         numKeysReturned_ = BinaryConverter.byteArrayToInt(defInfo, 0);
  190.         keyFieldsReturned_ = new int[numKeysReturned_];
  191.         keyTypesReturned_ = new char[numKeysReturned_];
  192.         keyLengthsReturned_ = new int[numKeysReturned_];
  193.         keyOffsetsReturned_ = new int[numKeysReturned_];
  194.         
  195.         offset = 4;
  196.         for (int i = 0; i < numKeysReturned_; ++i)
  197.         {
  198.             keyFieldsReturned_[i] = BinaryConverter.byteArrayToInt(defInfo, offset + 4);
  199.             keyTypesReturned_[i] = conv.byteArrayToString(defInfo, offset + 8, 1).charAt(0); // 'C' or 'B'
  200.             keyLengthsReturned_[i] = BinaryConverter.byteArrayToInt(defInfo, offset + 12);
  201.             keyOffsetsReturned_[i] = BinaryConverter.byteArrayToInt(defInfo, offset + 16);
  202.             offset += 20;
  203.         }
  204.         
  205.         // List information returned.
  206.         return parameters[5].getOutputData();
  207.     }
  208.  
  209.     @Override
  210.     protected Object[] formatOutputData(byte[] data, int recordsReturned, int recordLength)
  211.             throws AS400SecurityException, ErrorCompletingRequestException,
  212.             InterruptedException, IOException, ObjectDoesNotExistException {
  213.         int number = recordsReturned;  // request entire list
  214.         
  215.         CharConverter conv = new CharConverter(system_.getCcsid(), system_);
  216.         
  217.         SubsystemJobListItem[] listItems = new SubsystemJobListItem[number];
  218.         subsystemJobs_ = new Job[number];
  219.         String currentUser = null;
  220.         String functionName = null;
  221.         String functionType = null;
  222.         String messageReply = null;
  223.         byte[] messageKey = null;
  224.         String qualMessageQueue = null;
  225.         String qualSubsystem = null;
  226.         TreeMap keyValues = new TreeMap();
  227.         for (int i = 0, offset = 0; i < listItems.length; ++i, offset += recordLength)
  228.         {
  229.             String jobName = conv.byteArrayToString(data, offset, 10);
  230.             String jobUser = conv.byteArrayToString(data, offset + 10, 10);
  231.             String jobNumber = conv.byteArrayToString(data, offset + 20, 6);
  232.             String status = conv.byteArrayToString(data, offset + 26, 4);
  233.             String jobType = conv.byteArrayToString(data, offset + 30, 1);
  234.             String jobSubtype = conv.byteArrayToString(data, offset + 31, 1);
  235.             
  236.             for (int j = 0; j < numKeysReturned_; ++j)
  237.             {
  238.                  int keyOffset = keyOffsetsReturned_[j];
  239.                  if (keyTypesReturned_[j] == 'C')
  240.                  {    
  241.                      String value = conv.byteArrayToString(data, offset + keyOffset, keyLengthsReturned_[j]);
  242.                      if(keyFieldsReturned_[j] == 305 ) currentUser = value;
  243.                      if(keyFieldsReturned_[j] == 601 ) functionName = value;
  244.                      if(keyFieldsReturned_[j] == 602 ) functionType = value;
  245.                      if(keyFieldsReturned_[j] == 1307) messageReply = value;
  246.                      if(keyFieldsReturned_[j] == 1309) qualMessageQueue = value;
  247.                      if(keyFieldsReturned_[j] == 1906) qualSubsystem = value;
  248.                      if(keyFieldsReturned_[j] == 1308)
  249.                      {
  250.                          byte[] msgKey = new byte[4];
  251.                          System.arraycopy(data, offset + keyOffset, msgKey, 0, 4);
  252.                          messageKey = msgKey;
  253.                      }
  254.                      if(j > 6){
  255.                          if(keyFieldsReturned_[j] == 312 || keyFieldsReturned_[j] == 313 ||
  256.                                  keyFieldsReturned_[j] == 315 || keyFieldsReturned_[j] == 317 ||
  257.                                  keyFieldsReturned_[j] == 414 || keyFieldsReturned_[j] == 415 ||
  258.                                  keyFieldsReturned_[j] == 416 || keyFieldsReturned_[j] == 417 ||
  259.                                  keyFieldsReturned_[j] == 1609)
  260.                              keyValues.put(keyFieldsReturned_[j], new Long(BinaryConverter.byteArrayToLong(data, offset + keyOffset))) ;
  261.                          else
  262.                              keyValues.put(keyFieldsReturned_[j], value) ;
  263.                      }
  264.                  }
  265.                  else
  266.                  {
  267.                      if ((keyFieldsReturned_[j] == Job.TEMP_STORAGE_USED_LARGE))
  268.                          keyValues.put(keyFieldsReturned_[j], new Long(BinaryConverter.byteArrayToUnsignedInt(data, offset + keyOffset))) ;
  269.                      else
  270.                          keyValues.put(keyFieldsReturned_[j], new Integer(BinaryConverter.byteArrayToInt(data, offset + keyOffset))) ;
  271.                  }        
  272.             }
  273.             listItems[i] = new SubsystemJobListItem(jobName, jobUser, jobNumber,
  274.                         status, jobType,jobSubtype, currentUser, functionName, functionType,
  275.                         messageReply, messageKey, qualMessageQueue, qualSubsystem);
  276.             subsystemJobs_[i] = new Job(this.getSystem(), jobName, jobUser, jobNumber);
  277.             
  278.             listItems[i].setKeyValues(keyValues);
  279.         }
  280.         return listItems;        
  281.     }
  282.  
  283.     @Override
  284.     protected int getBestGuessReceiverSize(int number) {        
  285.         return 300 * number;
  286.     }
  287.     
  288. }
  289. ============================================================================
  290. ///////////////////////////////////////////////////////////////////////////////
  291. //
  292. //
  293. // Filename: SubsystemJobListItem.java
  294. //
  295. // Author  : Vengoal Chang
  296. // 
  297. // Date    : 2015/07/01
  298. //
  299. //
  300. ///////////////////////////////////////////////////////////////////////////////
  301. package com.vengoal.as400.list;
  302.  
  303. import java.util.Iterator;
  304. import java.util.Map;
  305. import java.util.Set;
  306. import java.util.TreeMap;
  307.  
  308. import com.ibm.as400.access.BinaryConverter;
  309.  
  310. public class SubsystemJobListItem {
  311.     public static final  int ACTIVE_JOB_STATUS_FOR_JOBS_ENDING     =  103; // Active job status for jobs ending
  312.     public static final  int CURRENT_USER                          =  305; // Current user profile
  313.     public static final  int CPU_TIME_USED_LARGE                   =  312; // Processing unit time used - total for the job
  314.     public static final  int CPU_TIME_USED_FOR_DATABASE            =  313; // Processing unit time used for database - total for the job (Deprecated)
  315.     public static final  int ELAPSED_CPU_PERCENT_USED              =  314; // Processing unit used -  percent during the elapsed time (job)
  316.     public static final  int ELAPSED_CPU_TIME_USED                 =  315; // Processing unit used - time during the elapsed time (job)
  317.     public static final  int ELAPSED_CPU_PERCENT_USED_FOR_DATABASE =  316; // Processing unit used for database - percent during the elapsed time (job) (Deprecated)
  318.     public static final  int ELAPSED_CPU_TIME_USED_FOR_DATABASE    =  317; // Processing unit used for database - time during the elapsed time (job) (Deprecated)
  319.     public static final  int DATE_ENTERED_SYSTEM                   =  402; // Date and time job entered system
  320.     public static final  int ELAPSED_DISK_IO                       =  414; // Disk I/O count during the elapsed time (job)
  321.     public static final  int DISK_IO                               =  415; // Disk I/O count - total for the job
  322.     public static final  int ELAPSED_DISK_IO_ASYNCH                =  416; // Disk I/O count during the elapsed time - asynchronous I/O (job)
  323.     public static final  int ELAPSED_DISK_IO_SYNCH                 =  417; // Disk I/O count during the elapsed time - synchronous I/O (job)
  324.     public static final  int CONTROLLED_END_REQUESTED              =  502; // End status
  325.     public static final  int FUNCTION_NAME                         =  601; // Function name
  326.     public static final  int FUNCTION_TYPE                         =  602; // Function type
  327.     public static final  int INTERNAL_JOB_IDENTIFIER               =  902; // Internal job identifier
  328.     public static final  int ELAPSED_INTERACTIVE_RESPONSE_TIME     =  904; // Interactive response time - total during the elapsed time
  329.     public static final  int ELAPSED_INTERACTIVE_TRANSACTIONS      =  905; // Interactive transactions - count during the elapsed time
  330.     public static final  int JOB_USER_IDENTITY                     = 1012; // Job user identity
  331.     public static final  int JOB_END_REASON                        = 1014; // Job end reason
  332.     public static final  int JOB_LOG_PENDING                       = 1015; // Job log pending
  333.     public static final  int JOB_TYPE_ENHANCED                     = 1016; // Job type - enhanced
  334.     public static final  int MEMORY_POOL                           = 1306; // Memory pool name
  335.     public static final  int MESSAGE_REPLY                         = 1307; // Message reply
  336.     public static final  int MESSAGE_KEY                           = 1308; // Message key, when active job waiting for a message
  337.     public static final  int MESSAGE_QUEUE                         = 1309; // Message queue name - qualified, when active job waiting for a message
  338.     public static final  int MESSAGE_QUEUE_ASP                     = 1310; // Message queue library ASP device name, when active job waiting for a message
  339.     public static final  int ELAPSED_PAGE_FAULTS                   = 1609; // Page fault count during the elapsed time (job)
  340.     public static final  int RUN_PRIORITY                          = 1802; // Run priority (job)
  341.     public static final  int SUBSYSTEM                             = 1906; // Subsystem description name - qualified
  342.     public static final  int SERVER_TYPE                           = 1911; // Server type
  343.     public static final  int SPOOLED_FILE_ACTION                   = 1982; // Spooled file action
  344.     public static final  int THREAD_COUNT                          = 2008; // Thread count
  345.     public static final  int TEMP_STORAGE_USED_LARGE               = 2009; // Temporary storage used, in megabytes(from V7R2)
  346.     
  347.     private String jobName;
  348.     private String jobUser;
  349.     private String jobNumber;
  350.     private String status;
  351.     private String jobType;
  352.     private String jobSubtype;
  353.     private String currentUser;      // key 305
  354.     private String functionName;     // key 601
  355.     private String functionType;     // key 602
  356.     private String messageReply;     // key 1307
  357.     private byte[] messageKey;       // key 1308
  358.     private String qualMessageQueue; // key 1309
  359.     private String qualSubsystem;    // key 1906
  360.     private TreeMap keyValues = new TreeMap(); // key others
  361.     
  362.     public SubsystemJobListItem(String jobName, String jobUser, String jobNumber,
  363.             String status, String jobType,String jobSubtype, String currentUser, String functionName,
  364.             String functionType,
  365.             String messageReply, byte[] messageKey, String qualMessageQueue, String qualSubsystem) {    
  366.         this.jobName = jobName;
  367.         this.jobUser = jobUser;
  368.         this.jobNumber = jobNumber;
  369.         this.status = status;
  370.         this.jobType = jobType;
  371.         this.jobSubtype = jobSubtype;
  372.         this.currentUser = currentUser;
  373.         this.functionName = functionName;
  374.         this.functionType = functionType;
  375.         this.messageReply = messageReply;
  376.         this.messageKey = messageKey;
  377.         this.qualMessageQueue = qualMessageQueue;
  378.         this.qualSubsystem = qualSubsystem;        
  379.     }
  380.     
  381.     public Object getObject(int key){
  382.         return keyValues.get(key);
  383.     }
  384.     
  385.     public void setKeyValues(TreeMap keyValues){
  386.         this.keyValues = keyValues;
  387.     }
  388.  
  389.     public String getJobName() {
  390.         return jobName;
  391.     }
  392.  
  393.     public String getJobUser() {
  394.         return jobUser;
  395.     }
  396.  
  397.     public String getJobNumber() {
  398.         return jobNumber;
  399.     }
  400.  
  401.     public String getStatus() {
  402.         return status;
  403.     }
  404.  
  405.     public String getJobType() {
  406.         return jobType;
  407.     }
  408.  
  409.     public String getJobSubtype() {
  410.         return jobSubtype;
  411.     }
  412.  
  413.     public String getCurrentUser() {
  414.         return currentUser;
  415.     }    
  416.     
  417.     public String getFunctionName() {
  418.         return functionName;
  419.     }    
  420.  
  421.     public String getFunctionType() {
  422.         return functionType;
  423.     }
  424.  
  425.     public String getMessageReply() {
  426.         return messageReply;
  427.     }
  428.  
  429.     public byte[] getMessageKey() {
  430.         return messageKey;
  431.     }
  432.  
  433.     public String getQualMessageQueue() {
  434.         return qualMessageQueue;
  435.     }
  436.  
  437.     public String getQualSubsystem() {
  438.         return qualSubsystem;
  439.     }
  440.     
  441.     public String toString(){
  442.         StringBuffer strBuf = new StringBuffer();
  443.         strBuf.append(jobName).append("/");
  444.         strBuf.append(jobUser).append("/");
  445.         strBuf.append(jobNumber).append(",");
  446.         strBuf.append(status).append(",");
  447.         strBuf.append(jobType).append(",");
  448.         strBuf.append(jobSubtype).append(",");
  449.         strBuf.append("305=" + currentUser).append(",");
  450.         strBuf.append("601=" + functionName).append(",");
  451.         strBuf.append("602=" + functionType).append(",");
  452.         strBuf.append("1307=" + messageReply).append(",");
  453.         strBuf.append("1308(MSGKEY 4 bytes hex string)=" + BinaryConverter.bytesToHexString(messageKey)).append(",");
  454.         strBuf.append("1309=" + qualMessageQueue).append(",");
  455.         strBuf.append("1906=" + qualSubsystem);
  456.         if(keyValues.size() > 0){
  457.              Set set = keyValues.entrySet();
  458.              Iterator i = set.iterator();
  459.              while(i.hasNext()) {                 
  460.                  Map.Entry me = (Map.Entry)i.next();
  461.                  strBuf.append("," + me.getKey() + "=" + me.getValue());
  462.             }
  463.         }
  464.         return strBuf.toString();
  465.     }
  466. }
  467. ============================================================================
  468. //////////////////////////////////////////////////////////////////////////////
  469. //
  470. //
  471. // Filename: SubsystemJobOpenListTest.java
  472. //
  473. // Author  : Vengoal Chang
  474. // 
  475. // Date    : 2015/07/01
  476. //
  477. //
  478. ///////////////////////////////////////////////////////////////////////////////
  479. package com.vengoal.as400.list;
  480.  
  481. import java.util.Enumeration;
  482.  
  483. import com.ibm.as400.access.AS400;
  484. import com.ibm.as400.access.CallStackEntry;
  485. import com.ibm.as400.access.Job;
  486. import com.vengoal.as400.common.MessageUtil;
  487.  
  488. public class SubsystemJobOpenListTest {
  489.  
  490.     public static void main(String[] args) {
  491.         AS400 as400 = new AS400("as400ip", "user", "pass");
  492.         String subsystem = "QBATCH";
  493.         SubsystemJobOpenList list = new SubsystemJobOpenList(as400, subsystem);
  494.         list.addJobAttributeToRetrieve(SubsystemJobListItem.MEMORY_POOL);
  495.         list.addJobAttributeToRetrieve(SubsystemJobListItem.RUN_PRIORITY);
  496.         list.addJobAttributeToRetrieve(SubsystemJobListItem.DATE_ENTERED_SYSTEM);
  497.         list.addJobAttributeToRetrieve(SubsystemJobListItem.JOB_LOG_PENDING);
  498.         list.addJobAttributeToRetrieve(SubsystemJobListItem.JOB_TYPE_ENHANCED);
  499.         list.addJobAttributeToRetrieve(SubsystemJobListItem.SPOOLED_FILE_ACTION);
  500.         list.addJobAttributeToRetrieve(SubsystemJobListItem.THREAD_COUNT);
  501.         list.addJobAttributeToRetrieve(SubsystemJobListItem.CPU_TIME_USED_LARGE);
  502.         list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_CPU_PERCENT_USED);
  503.         list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_CPU_TIME_USED);
  504.         list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_PAGE_FAULTS);
  505.         list.addJobAttributeToRetrieve(SubsystemJobListItem.DISK_IO);
  506.         list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_DISK_IO_ASYNCH);
  507.         list.addJobAttributeToRetrieve(SubsystemJobListItem.ELAPSED_DISK_IO_SYNCH);
  508.         try {
  509.             list.open();
  510.             Enumeration items = list.getItems();
  511.             while (items.hasMoreElements())
  512.             {
  513.                 SubsystemJobListItem item = (SubsystemJobListItem)items.nextElement();
  514.                 System.out.println(item);
  515.                 if(item.getMessageReply().equalsIgnoreCase(Job.MESSAGE_REPLY_WAITING)){
  516.                     Job msgwJob = new Job(as400, item.getJobName(), item.getJobUser(), item.getJobNumber());
  517.                     CallStackEntry[] callstackEntry = msgwJob.getCallStack(Job.INITIAL_THREAD);
  518.                     System.out.println("job call stack as following:");
  519.                     for(int i = 0; i< callstackEntry.length; ++i){
  520.                         System.out.println(callstackEntry[i].getProgramLibrary() + "/" + callstackEntry[i].getProgramName() + " " + callstackEntry[i].getProcedureName());
  521.                     }
  522.                 }
  523.                 System.out.println("Spooled file action=" + item.getObject(SubsystemJobListItem.SPOOLED_FILE_ACTION));
  524.                 System.out.println("====================================");
  525.             }
  526.             
  527.             Job[] subsystemJobs = list.getSubsystemJobs();            
  528.             if(subsystemJobs != null){
  529.                 for(int i =0; i < subsystemJobs.length; ++i){
  530.                     // do your work related job 
  531.                     System.out.println(subsystemJobs[i].getNumber() + "/" + subsystemJobs[i].getUser() + "/" + subsystemJobs[i].getName());
  532.                 }
  533.             } else {
  534.                 System.out.println("Subsystem " + subsystem + " is inactive or not exist");
  535.             }
  536.             list.close();
  537.         } catch (Exception e) {
  538.             e.printStackTrace();
  539.         }
  540.     }
  541. }
  542.  
© 2004-2019 by midrange.com generated in 0.143s valid xhtml & css