星期四, 11月 09, 2023

2014-12-23 如何以 java 取得 data queue 的所有屬性?(Retreive data queue description with API QMHQRDQD)


如何以 java 取得 data queue 的所有屬性?(Retreive data queue description with API QMHQRDQD)

RtvDtaqD.java
     



/* ==================================================================*/
/*                                                                   */
/*  Program . . : RtvDtaqD.java                                      */
/*  Description : Retrieve data queue description                    */
/*  Author  . . : Vengoal Chang                                      */
/*  Published . : AS400ePaper                                        */
/*  Date  . . . : December 23, 2014                                  */
/*                                                                   */
/* ==================================================================*/

package com.free400.vengoal.as400api;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Bin4;
import com.ibm.as400.access.AS400Exception;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.CharConverter;
import com.ibm.as400.access.DateTimeConverter;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;
import com.ibm.as400.access.ServiceProgramCall;
import com.ibm.as400.access.Trace;

public class RtvDtaqD {
	private static final int PAD_LIMIT = 8192;
	private static final AS400Bin4 intConverter_ = new AS400Bin4();
	public static Calendar cal = Calendar.getInstance();
	public static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

private static ProgramParameter[] buildProgramParameters(AS400 as400, String dtaqname, String dtaqlib) throws Exception {
		
		ProgramParameter[] parameterList = new ProgramParameter[4];
		parameterList[0] = new ProgramParameter(120);
		
		parameterList[1] = new ProgramParameter(intConverter_.toBytes(120));		
			
		AS400Text text8 = new AS400Text(8, as400);
		parameterList[2] = new ProgramParameter(text8.toBytes("RDQD0100"));	
		
		AS400Text text20 = new AS400Text(20, as400);
		byte[] dtaqNameLibBytes = text20.toBytes(padRight(dtaqname, 10) + padRight(dtaqlib, 10));
		parameterList[3] = new ProgramParameter(dtaqNameLibBytes);
				
		return parameterList;			
	}

	private static void rtvDtaqDesc(AS400 as400, String dtaqname, String dtaqlib){
		try{
			CharConverter charConverter = new CharConverter(as400.getCcsid(), as400);
			ProgramParameter[] parameters = buildProgramParameters(as400, dtaqname, dtaqlib);
			ProgramCall  rtvDtaqPgmDCall = new ProgramCall(as400, "/QSYS.LIB/QMHQRDQD.PGM", parameters);
			//Trace.setTraceAllOn(true);
			//Trace.setTraceOn(true);
			if (rtvDtaqPgmDCall.run() != true) {
				throw new AS400Exception(rtvDtaqPgmDCall.getMessageList());
			} else {
				byte[] rcvVar = parameters[0].getOutputData();
				int maxentlen = intConverter_.toInt(rcvVar, 8);
				System.out.println("Maximum entry length: " + maxentlen );
				
				int keylen = intConverter_.toInt(rcvVar, 12);
				System.out.println("Key length: " + keylen );
				
				String sequence = charConverter.byteArrayToString(rcvVar, 16, 1);
				System.out.println("Sequence: " + sequence );
				
				String senderid = charConverter.byteArrayToString(rcvVar, 17, 1); 
				System.out.println("Include sender ID: " + senderid );
				
				String forceindicator = charConverter.byteArrayToString(rcvVar, 18, 1);
				System.out.println("Force indicator: " + forceindicator );
				
				String text = charConverter.byteArrayToString(rcvVar, 19, 50);
				System.out.println("Text: " + text );
				
				String typeOfDq = charConverter.byteArrayToString(rcvVar, 69, 1);
				System.out.println("Type of data queue: " + typeOfDq );
				
				String autoReclaim = charConverter.byteArrayToString(rcvVar, 70, 1);
				System.out.println("Automatic Reclaim: " + autoReclaim );
				
				String eforceDqLck = charConverter.byteArrayToString(rcvVar, 71, 1);
				System.out.println("Enforce data queue locks: " + eforceDqLck );
				
				int nbrOfMsg = intConverter_.toInt(rcvVar, 72);
				System.out.println("Number of messages: " + nbrOfMsg );
				
				int nbrOfMsgAlc = intConverter_.toInt(rcvVar, 76);
				System.out.println("Number of entries currently allocated: " + nbrOfMsgAlc );			
				
				String dqname = charConverter.byteArrayToString(rcvVar, 80, 10);
				System.out.println("Data queue name used: " +dqname );
				
				String dqlib = charConverter.byteArrayToString(rcvVar, 90, 10);
				System.out.println("Data queue library used: " + dqlib );
				
				int maxNbrOfEntAlw = intConverter_.toInt(rcvVar, 100);
				System.out.println("Maximum number of entries allowed: " + maxNbrOfEntAlw );	
				
				int inlNbrOfEnt = intConverter_.toInt(rcvVar, 104);
				System.out.println("Initial number of entries: " + inlNbrOfEnt );
				
				int maxNbrOfEntSpc = intConverter_.toInt(rcvVar, 108);
				System.out.println("Maximum number of entries specified: " + maxNbrOfEntSpc );
				
				DateTimeConverter dtc = new DateTimeConverter(as400);
				// System current date and time
		        byte[] systemDtsByte = new byte[8];
		        System.arraycopy(rcvVar, 112, systemDtsByte, 0, 8);
		        Date sysDate = dtc.convert(systemDtsByte, "*DTS");
		        String systemTimeStr=null;
		        if (sysDate != null){
		        	cal.setTime(sysDate);
		        	systemTimeStr = df.format(cal.getTime());
		        }
		        System.out.println("Last reclaim date and time: " + systemTimeStr );

			}
			
			} catch(Exception e){
				e.printStackTrace();
			}
	}

	public static String padRight(String s, int n) {
		return String.format("%1$-" + n + "s", s);
	}

	public static void main(String[] args)  {		
		AS400 as400 = new AS400("as400ip", "user", "password");
		rtvDtaqDesc(as400,  "DTAQ", "QGPL");
	}

}







參照: Retrieve Data Queue Description (QMHQRDQD) API




沒有留言: