如何编写PCF命令以获取具有条件的通道状态?

时间:2016-04-23 00:23:35

标签: java ibm-mq pcf

有没有办法编写PCF程序来获取群集发送者/接收者频道的频道状态,这些频道位于"运行"状态?
我有这样的东西,只给我一个频道的频道状态!

 // 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  + ")"); 

以上代码仅为一个频道而非所有频道提供频道状态。这有什么不对?

2 个答案:

答案 0 :(得分:3)

您的代码的PCF部分看起来很好,但是打印出的结果是错误的代码。

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

你有一个for循环围绕所有的响应,但是println在for循环之外,因此只打印出最终响应的结果。

答案 1 :(得分:1)

抓住我的名为MQ Channel Monitor的开源项目。下载源代码并查看“PCFChlStatus.java”#39;文件。有一个名为getMCAStatus()的方法,它基本上就是你所追求的。