Search code examples
javaibm-mqpcf

How to write PCF command to get channel status with a condition?


Is there a way to write a PCF program to get channel status for Cluster Sender/Receiver channels which are in "Running" status?
I have something like this which gives me channel status of only one channel!

 // send the request and collect the responses 
    String checkStatus="";
    String channelName ="";
 // build a request 
    request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS); 
 // add a parameter designating the name of the channel for which status is requested 
    request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, "TO.*"); 
 // add a parameter designating the instance type (current) desired 
    request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE, CMQC.MQOT_CURRENT_CHANNEL); 

    responses = agent.send(request); 
    for (int j = 0; j < responses.length; j++) { 
         //  get the channel name and trim the spaces 
        String temp ="";
        temp = responses[j].getStringParameterValue(CMQCFC.MQCACH_CHANNEL_NAME); 
        channelName = temp.trim(); 

        int chlStatus = responses[j].getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS); 
        //System.out.println("channel status: " + chlStatus); 
        String[] chStatusText = { 
            "", "MQCHS_BINDING", "MQCHS_STARTING", "MQCHS_RUNNING", 
                "MQCHS_STOPPING", "MQCHS_RETRYING", "MQCHS_STOPPED", 
                "MQCHS_REQUESTING", "MQCHS_PAUSED", 
                "", "", "", "", "MQCHS_INITIALIZING" 
        }; 
        checkStatus = chStatusText[chlStatus]; 
        //System.out.println("channel status: " + checkStatus); 
    } 
    System.out.println("chl: " + channelName + " STATUS: " + checkStatus  + ")"); 

The above code gives channel status for only one channel and not all the channels. What is wrong here?


Solution

  • The PCF part of your code looks fine, but the printing out of the result is the code in error.

    responses = agent.send(request); 
    for (int j = 0; j < responses.length; j++) { 
        :
        :
        checkStatus = chStatusText[chlStatus];
    } 
    System.out.println("chl: " + channelName + " STATUS: " + checkStatus  + ")"); 
    

    You have a for loop going round all the responses, but then the println is outside the for loop and thus is only printing out the result for the final response.