1

I'm using Data Queues in AS400/iSeries and read from one using jdbc jt400 library.

As it's a producer(AS400)/consumer(myapp) pattern, I want to check how many entries in the data queue are now, and measure if my app is working fast enough or I need to change something.

I can get the max length/size of the data queue, but not the current length/size.

How can I get or calculate that value?

I can use a rpg program and call it, but prefer a jt400/jdbc solution.

Thanks

I edit this question to add code that should do this task but I get an Exception:

    String pname = "/QSYS.LIB/QMHQRDQD.PGM";
    int param0_size = 120; // RDQD0100 size
    int size = -1;
    ProgramCall spgm = new ProgramCall(as400);
    ProgramParameter[] params = new ProgramParameter[4];
    params[0] = new ProgramParameter(param0_size);
    AS400Bin4 length = new AS400Bin4();
    params[1]  = new ProgramParameter(length.toBytes(param0_size));
    AS400Text formatname = new AS400Text(8);
    params[2] = new ProgramParameter(formatname.toBytes("RDQD0100"));
    AS400Text dataqueuename = new AS400Text(20);
    params[3] = new ProgramParameter(dataqueuename.toBytes("DTQDTQ    LIBFIC    "));
    byte[] RDQD0100 = new byte[120];

    try {
        spgm.setProgram(pname, params);
        if (spgm.run() == true) {
            AS400Text out = new AS400Text(param0_size);
            RDQD0100 = out.toBytes(params[0].getOutputData());
            ByteBuffer bb = ByteBuffer.wrap(RDQD0100);
            bb.position(76);  // Number of entries currently allocated
            size = bb.getInt();
        }
    }
    catch (Exception e){
        Logger.error(" ERROR {} ", e);
    }

    return size;

I get always -1 as answer and an Exception in line RDQD0100 = out.toB..

The exception is

java.lang.ClassCastException: [B cannot be cast to java.base/java.lang.String

Any clues? Thanks again

Eduardo
  • 33
  • 5

2 Answers2

2

Oks, I've found the fail on my code added to my question and want to share the solution.

This code returns the current number of entries in the dataqueue DTQDTQ on library LIBFIC or -1 if an error/exception happened.

int getDQSize() {

    String pname = "/QSYS.LIB/QMHQRDQD.PGM";
    int param0_size = 120; // RDQD0100 size
    int size = -1;
    ProgramCall spgm = new ProgramCall(as400);
    ProgramParameter[] params = new ProgramParameter[4];
    params[0] = new ProgramParameter(param0_size);
    AS400Bin4 length = new AS400Bin4();
    params[1]  = new ProgramParameter(length.toBytes(param0_size));
    AS400Text formatname = new AS400Text(8);
    params[2] = new ProgramParameter(formatname.toBytes("RDQD0100"));
    AS400Text dataqueuename = new AS400Text(20);
    params[3] = new ProgramParameter(dataqueuename.toBytes("DTQDTQ    LIBFIC    "));
    byte[] RDQD0100 = new byte[120];

    try {
        spgm.setProgram(pname, params);
        if (spgm.run() == true) {
            ByteBuffer bb = ByteBuffer.wrap(params[0].getOutputData());
            bb.position(72);
            size = bb.getInt();
        }
    }
    catch (Exception e){
        Logger.error(" ERROR {} ", e);
    }

    return size;
}

Thanks again to David G

Eduardo
  • 33
  • 5
  • FWIW: I recommend defining the call in PCML. It's easier to define & maintain than the method you're using. – David G Jan 24 '19 at 18:23
1

Using base JT400, there doesn't appear to be a way to get the number of entries in a data queue.

You could use the QMHQRDQD api to get the number of messages in the queue.

David G
  • 3,940
  • 1
  • 22
  • 30