com.ibm.mq.pcf
Class PCFAgent

java.lang.Object
  |
  +--com.ibm.mq.pcf.PCFAgent
Direct Known Subclasses:
PCFMessageAgent

public class PCFAgent
extends java.lang.Object

General-purpose agent for sending PCF queries to a queue manager. A PCFAgent maintains a single queue manager connection and provides a simple method for sending PCF requests and returning the set of response messages. The following example uses a PCFAgent to obtain the list of local queues on the queue manager.

 
 	PCFAgent 	agent = new PCFAgent ("localhost", 1414, "CLIENT");
 	MQMessage [] 	responses;
 	PCFParameter [] parameters = 
 			{
 				new MQCFST (CMQC.MQCA_Q_NAME, "*"), 
 				new MQCFIN (CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL)
 			};
 	MQCFH 		cfh;
 	MQCFSL 		cfsl;
 
 	responses = agent.send (CMQCFC.MQCMD_INQUIRE_Q_NAMES, parameters);
 
 	cfh = new MQCFH (responses [0]);
 
 	if (cfh.reason == 0)
 	{
 		cfsl = new MQCFSL (responses [0]);
 
 		for (int i = 0; i < cfsl.strings.length; i++)
 		{
 			System.out.println ("Queue: " + cfsl.strings [i]);
 		}
 	}
 	else
 	{
 		throw new MQException (cfh.compCode, cfh.reason, agent);
 	}
 
 

New in version 2.0:

Note: The PCFMessageAgent class (a subclass of PCFAgent) introduced with version 2.0 of this support pack provides a higher-level mechanism for sending PCF messages that is simpler to use. It uses the PCFMessage class (also new in version 2.0) to encapsulate PCF requests and responses, which avoids the need for the application to directly manipulate MQSeries messages and PCF header and parameters structures.

New in version 2.2:

Version:
2.2
Author:
Chris Markes
See Also:
PCFMessageAgent

Field Summary
protected  com.ibm.mq.MQQueue adminQueue
           
static java.lang.String copyright
           
protected  int expiryTime
           
protected  com.ibm.mq.MQQueueManager qmanager
           
protected  int qmanager_level
           
protected  java.lang.String qmanager_name
           
protected  com.ibm.mq.MQQueue replyQueue
           
 java.lang.String replyQueueName
           
protected  int waitInterval
           
 
Constructor Summary
PCFAgent()
          Default constructor.
PCFAgent(com.ibm.mq.MQQueueManager qmanager)
          Initializes a new PCFAgent with an existing queue manager connection.
PCFAgent(java.lang.String qmanager)
          Initializes a new PCFAgent with a bindings connection to a queue manager.
PCFAgent(java.lang.String host, int port, java.lang.String channel)
          Initializes a new PCFAgent with a client connection to a queue manager.
 
Method Summary
 void connect(com.ibm.mq.MQQueueManager qmanager)
          Adopts a connection to a queue manager.
 void connect(java.lang.String qmanager)
          Establishes a bindings connection to a queue manager.
 void connect(java.lang.String host, int port, java.lang.String channel)
          Establishes a client connection to a queue manager.
 void disconnect()
          Frees queue manager resources, and drops the current queue manager connection.
 java.lang.String getQManagerName()
          Returns the name of the queue manager (if connected).
protected  void open(com.ibm.mq.MQQueueManager qmanager, boolean external)
           
 com.ibm.mq.MQMessage[] send(int command, PCFParameter[] parameters)
          Sends a PCF query to the connected queue manager and returns the response.
 void setWaitInterval(int seconds)
          Set the wait interval for PCF responses.
 
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

replyQueueName

public final java.lang.String replyQueueName

expiryTime

protected int expiryTime

waitInterval

protected int waitInterval

qmanager

protected com.ibm.mq.MQQueueManager qmanager

qmanager_level

protected int qmanager_level

qmanager_name

protected java.lang.String qmanager_name

adminQueue

protected com.ibm.mq.MQQueue adminQueue

replyQueue

protected com.ibm.mq.MQQueue replyQueue
Constructor Detail

PCFAgent

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

PCFAgent

public PCFAgent(com.ibm.mq.MQQueueManager qmanager)
         throws com.ibm.mq.MQException
Initializes a new PCFAgent 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

PCFAgent

public PCFAgent(java.lang.String host,
                int port,
                java.lang.String channel)
         throws com.ibm.mq.MQException
Initializes a new PCFAgent 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

PCFAgent

public PCFAgent(java.lang.String qmanager)
         throws com.ibm.mq.MQException
Initializes a new PCFAgent 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

connect

public void connect(com.ibm.mq.MQQueueManager qmanager)
             throws com.ibm.mq.MQException
Adopts a connection to a queue manager.
Parameters:
qmanager - an existing queue manager connection
Throws:
com.ibm.mq.MQException - if the queue manager cannot be accessed

connect

public void connect(java.lang.String host,
                    int port,
                    java.lang.String channel)
             throws com.ibm.mq.MQException
Establishes 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

connect

public void connect(java.lang.String qmanager)
             throws com.ibm.mq.MQException
Establishes a bindings connection to a queue manager.
Parameters:
qmanager - the queue manager name
Throws:
com.ibm.mq.MQException - if the connection cannot be established

open

protected void open(com.ibm.mq.MQQueueManager qmanager,
                    boolean external)
             throws com.ibm.mq.MQException

disconnect

public void disconnect()
                throws com.ibm.mq.MQException
Frees queue manager resources, and drops the current queue manager connection. If the queue manager connection was established externally and passed by the caller using either the PCFAgent(MQQueueManager) constructor or the connect(MQQueueManager) method, the PCFAgent assumes the queue manager connection is externally managed and leaves the originator to disconnect it. If the PCFAgent established the queue manager connection itself, it disconnects the queue manager by invoking its disconnect() method.
Throws:
com.ibm.mq.MQException - if there is a problem disconnecting

send

public com.ibm.mq.MQMessage[] send(int command,
                                   PCFParameter[] parameters)
                            throws com.ibm.mq.MQException,
                                   java.io.IOException
Sends a PCF query to the connected queue manager and returns the response. An MQCFH is generated for the request, containing the specified command identifier and appropriate parameter count.
Parameters:
command - the PCF command identifier
parameters - an array of integer or string parameter or parameter array structures (type MQCFIN, MQCFIL, MQCFST or MQCFSL).
Returns:
an array of PCF response messages. A single PCF request can generate multiple replies.
Throws:
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

setWaitInterval

public void setWaitInterval(int seconds)
Set the wait interval for PCF responses. This determines both the expiry time for each PCF request sent by the agent and the time for which the agent will wait for the corresponding PCF response. The default is 30s. Zero is allowed; negative values are ignored.
Parameters:
seconds - the wait interval in seconds

getQManagerName

public java.lang.String getQManagerName()
Returns the name of the queue manager (if connected).
Returns:
the queue manager name