Sun GlassFish Message Queue 4.4 Developer's Guide for Java Clients

Composing Map Messages

Table 2–11 shows the methods available in the MapMessage interface for adding content to the body of a map message. Each of these methods takes two arguments, a name string and a primitive or string value of the appropriate type, and adds the corresponding name-value pair to the message body: for example,

StreamMessage  outMsg = mySession.createMapMessage();
outMsg.setInt("The Meaning of Life", 42);
Table 2–11 Map Message Composition Methods

Name 

Description 

setInt

Store integer in message map by name 

setByte

Store byte value in message map by name 

setBytes

Store byte array in message map by name 

setShort

Store short integer in message map by name 

setLong

Store long integer in message map by name 

setFloat

Store floating-point value in message map by name 

setDouble

Store double-precision value in message map by name 

setBoolean

Store boolean value in message map by name 

setChar

Store character in message map by name 

setString

Store string in message map by name 

setObject

Store object in message map by name 

Like stream messages, map messages provide a convenience method (setObject) for dealing with values whose type is determined dynamically at execution time: for example, the statements

Integer  meaningOfLife = new Integer(42);
outMsg.setObject("The Meaning of Life", meaningOfLife);

are equivalent to

outMsg.setInt("The Meaning of Life", 42);

The object supplied must be either a string object (class String) or an objectified primitive value of class Integer, Byte , Short, Long, Float, Double, Boolean, or Character; otherwise an exception (MessageFormatException) will be thrown.