Getting and setting attribute values in IBM MQ classes for Java
getXXX() and setXXX() methods are provided for many common attributes. Others can be accessed using the generic inquire() and set() methods.
For many of the common attributes, the classes MQManagedObject, MQDestination, MQQueue, MQTopic, MQProcess, and MQQueueManager contain getXXX() and setXXX() methods. These methods allow you to get and set their attribute values. Note that for MQDestination, MQQueue, and MQTopic, the methods work only if we specify the appropriate inquire and set flags when you open the object.
For less common attributes, the MQQueueManager, MQDestination, MQQueue, MQTopic,, and MQProcess classes all inherit from a class called MQManagedObject. This class defines the inquire() and set() interfaces.
When creating a new queue manager object by using the new operator, it is automatically opened for inquire. When we use the accessProcess() method to access a process object, that object is automatically opened for inquire. When we use the accessQueue() method to access a queue object, that object is not automatically opened for either inquire or set operations. This is because adding these options automatically can cause problems with some types of remote queues. To use the inquire, set, getXXX, and setXXX methods on a queue, we must specify the appropriate inquire and set flags in the openOptions parameter of the accessQueue() method. The same is true for destination and topic objects.
The inquire and set methods take three parameters:- selectors array
- intAttrs array
- charAttrs array
You do not need the SelectorCount, IntAttrCount, and CharAttrLength parameters that are found in MQINQ, because the length of an array in Java is always known. The following example shows how to make an inquiry on a queue:
// inquire on a queue final static int MQIA_DEF_PRIORITY = 6; final static int MQCA_Q_DESC = 2013; final static int MQ_Q_DESC_LENGTH = 64; int[] selectors = new int[2]; int[] intAttrs = new int[1]; byte[] charAttrs = new byte[MQ_Q_DESC_LENGTH] selectors[0] = MQIA_DEF_PRIORITY; selectors[1] = MQCA_Q_DESC; queue.inquire(selectors,intAttrs,charAttrs); System.out.println("Default Priority = " + intAttrs[0]); System.out.println("Description : " + new String(charAttrs,0));Parent topic: Writing IBM MQ classes for Java applications