com.ibm.mq.pcf
Class PCFMessageAgent

java.lang.Object
  |
  +--com.ibm.mq.pcf.PCFAgent
        |
        +--com.ibm.mq.pcf.PCFMessageAgent

public class PCFMessageAgent
extends PCFAgent

General-purpose agent for sending PCF queries to a queue manager. Like the PCFAgent it extends, a PCFMessageAgent maintains a single queue manager connection and provides a simple method for sending PCF requests and returning the set of response messages. The PCFMessageAgent uses the PCFMessage class for requests and replies, which avoids exposure to the details of underlying PCF header structures. The PCFMessageAgent also provides the capability to check the header contents of a PCF response and throw a PCFException if the response indicates an error.

The following example uses a PCFMessageAgent to obtain the list of local queues on the queue manager.

 
 import com.ibm.mq.pcf.*;
 
 ...
 
 try
 {
 	PCFMessageAgent agent = new PCFMessageAgent ("localhost", 1414, "CLIENT");
 	PCFMessage 	request = new PCFMessage (CMQCFC.MQCMD_INQUIRE_Q_NAMES);
 
 	request.addParameter (CMQC.MQCA_Q_NAME, "*");
 	request.addParameter (CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL);
 
 	PCFMessage [] 	responses = agent.send (request);
 	String [] 	names = (String []) responses [0].getParameterValue (CMQCFC.MQCACF_Q_NAMES);
 
 	for (int i = 0; i < names.length; i++)
 	{
 		System.out.println ("Queue: " + names [i]);
 	}
 }
 
 catch (PCFException pcfe)
 {
 	System.err.println ("PCF error: " + pcfe);
 }
 
 catch (MQException mqe)
 {
 	System.err.println (mqe);
 }
 
 catch (IOException ioe)
 {
 	System.err.println (ioe);
 }
 
 

New in version 2.2:

Version:
2.2
Author:
Chris Markes

Field Summary
static java.lang.String copyright
           
 
Fields inherited from class com.ibm.mq.pcf.PCFAgent
adminQueue, expiryTime, qmanager, qmanager_level, qmanager_name, replyQueue, replyQueueName, waitInterval
 
Constructor Summary
PCFMessageAgent()
          Default constructor.
PCFMessageAgent(com.ibm.mq.MQQueueManager qmanager)
          Initializes a new PCFMessageAgent with an existing queue manager connection.
PCFMessageAgent(java.lang.String qmanager)
          Initializes a new PCFMessageAgent with a bindings connection to a queue manager.
PCFMessageAgent(java.lang.String host, int port, java.lang.String channel)
          Initializes a new PCFMessageAgent with a client connection to a queue manager.
 
Method Summary
 PCFMessage[] send(PCFMessage request)
          Sends a PCF request to the connected queue manager and returns the response.
 PCFMessage[] send(PCFMessage request, boolean check)
          Sends a PCF request to the connected queue manager and returns the response.
 
Methods inherited from class com.ibm.mq.pcf.PCFAgent
connect, connect, connect, disconnect, getQManagerName, open, send, setWaitInterval
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
Constructor Detail

PCFMessageAgent

public PCFMessageAgent()
Default constructor. Initializes a new PCFMessageAgent with no queue manager connection.

PCFMessageAgent

public PCFMessageAgent(com.ibm.mq.MQQueueManager qmanager)
                throws com.ibm.mq.MQException
Initializes a new PCFMessageAgent with an existing queue manager connection.
Parameters:
qmanager - an existing queue manager connection
Throws:
com.ibm.mq.MQException - if the queue manager cannot be accessed

PCFMessageAgent

public PCFMessageAgent(java.lang.String host,
                       int port,
                       java.lang.String channel)
                throws com.ibm.mq.MQException
Initializes a new PCFMessageAgent with a client connection to a queue manager.
Parameters:
host - the hostname or IP address where the queue manager resides
port - the port on which the queue manager listens for incoming channel connections
channel - the client channel to use for the connection
Throws:
com.ibm.mq.MQException - if the connection cannot be established

PCFMessageAgent

public PCFMessageAgent(java.lang.String qmanager)
                throws com.ibm.mq.MQException
Initializes a new PCFMessageAgent with a bindings connection to a queue manager.
Parameters:
qmanager - the name of the queue manager
Throws:
com.ibm.mq.MQException - if the connection cannot be established
Method Detail

send

public PCFMessage[] send(PCFMessage request)
                  throws PCFException,
                         com.ibm.mq.MQException,
                         java.io.IOException
Sends a PCF request to the connected queue manager and returns the response. This is equivalent to an invocation of send(PCFMessage, boolean) with the boolean check flag set.
Parameters:
request - the PCF request message
Returns:
an array of PCF response messages. A single PCF request can generate multiple replies.
Throws:
PCFException - if the response indicates an error in PCF processing
com.ibm.mq.MQException - if there is a problem with the request or response
java.io.IOException - if there is a problem with reading or writing

send

public PCFMessage[] send(PCFMessage request,
                         boolean check)
                  throws PCFException,
                         com.ibm.mq.MQException,
                         java.io.IOException
Sends a PCF request to the connected queue manager and returns the response. If the check flag is set, the completion and reason codes in the PCF header (MQCFH) of first response message are checked, and a PCFException is thrown if they are other than MQCC_OK and MQRC_NONE respectively. The array of response messages is contained in the exception's exceptionSource field and can be inspected. Using the check flag, an application can choose whether to perform normal PCF response processing inside a try block where it can assume the response is successful, or to perform the introspection of the responses itself.
Parameters:
request - the PCF request message
check - if set, this method throws a PCFException if the response indicates a PCF error
Returns:
an array of PCF response messages. A single PCF request can generate multiple replies.
Throws:
PCFException - if the check flag is set and the response indicates an error in PCF processing by the command server
com.ibm.mq.MQException - if there is a problem sending the request or reading the response
java.io.IOException - if there is a problem with reading or writing