1 21 package com.presumo.jms.message; 22 23 import java.io.DataInput ; 24 import java.io.DataOutput ; 25 import java.io.IOException ; 26 27 import javax.jms.Destination ; 28 29 34 final class MessageHeader 35 { 36 private static final int JMS_DESTINATION = 1; 37 private static final int JMS_MESSAGEID = 2; 38 private static final int JMS_DELIVERYMODE = 4; 39 private static final int JMS_CORRELATION = 8; 40 private static final int JMS_EXPIRATION = 16; 41 private static final int JMS_TIMESTAMP = 32; 42 private static final int JMS_PRIORITY = 64; 43 private static final int JMS_REPLYTO = 128; 44 private static final int JMS_REDELIV = 256; 45 private static final int JMS_TYPE = 512; 46 private static final int JMS_SYSTEM_TYPE = 1024; 47 48 53 String jmsDestination; 59 MessageID jmsMessageID; 60 int jmsDeliveryMode; 61 MessageID jmsCorrelationID; 62 long jmsExpiration; 63 long jmsTimestamp; 64 int jmsPriority = javax.jms.Message.DEFAULT_PRIORITY; 65 String jmsReplyTo; 66 boolean jmsRedelivered; 67 String jmsType; 68 int jmsSystemMsgType; 69 70 private int bitMask; 71 72 MessageHeader() 76 { 77 super(); 78 } 79 80 81 85 public String toString() 86 { 87 StringBuffer result = new StringBuffer (); 88 result.append("Destination: "); 89 result.append( ((jmsDestination == null) ? "none" : jmsDestination) ); 90 result.append('\n'); 91 92 result.append("MessageID: " ); 93 result.append(jmsMessageID.toString()); 94 result.append('\n'); 95 if (jmsDeliveryMode == javax.jms.DeliveryMode.PERSISTENT) 96 result.append("PERSISTENT"); 97 else 98 result.append("NON-PERSITENT"); 99 result.append(": priority="); 100 result.append(jmsPriority); 101 if (jmsRedelivered) 102 result.append(" : REDELIVERED"); 103 result.append('\n'); 104 105 if (jmsCorrelationID != null) { 106 result.append("CorrelationID: "); 107 result.append(jmsCorrelationID.toString()); 108 result.append('\n'); 109 } 110 111 if (jmsReplyTo != null) { 112 result.append("ReplyTo: "); 113 result.append(jmsReplyTo.toString()); 114 result.append('\n'); 115 } 116 117 if (jmsExpiration != 0) { 118 result.append("Expiration: "); 119 result.append(jmsExpiration); 120 result.append('\n'); 121 } 122 123 if (jmsTimestamp != 0) { 124 result.append("Timestamp: "); 125 result.append(jmsTimestamp); 126 result.append('\n'); 127 } 128 129 return result.toString(); 130 } 131 132 136 139 final void marshal(DataOutput out) throws IOException 140 { 141 out.writeShort(bitMask); 142 143 if ((bitMask & JMS_DESTINATION) != 0) 144 out.writeUTF(jmsDestination); 145 146 if ((bitMask & JMS_MESSAGEID) != 0) 147 jmsMessageID.marshal(out); 148 149 if ((bitMask & JMS_DELIVERYMODE) != 0) 150 out.writeByte(jmsDeliveryMode); 151 152 if ((bitMask & JMS_CORRELATION) != 0) 153 jmsCorrelationID.marshal(out); 154 155 if ((bitMask & JMS_EXPIRATION) != 0) 156 out.writeLong(jmsExpiration); 157 158 if ((bitMask & JMS_TIMESTAMP) != 0) 159 out.writeLong(jmsTimestamp); 160 161 if ((bitMask & JMS_PRIORITY) != 0) 162 out.writeByte(jmsPriority); 163 164 if ((bitMask & JMS_REPLYTO) != 0) 165 out.writeUTF(jmsReplyTo.toString()); 166 167 if ((bitMask & JMS_REDELIV) != 0) 168 out.writeBoolean(jmsRedelivered); 169 170 if ((bitMask & JMS_TYPE) != 0) 171 out.writeUTF(jmsType); 172 if ((bitMask & JMS_SYSTEM_TYPE) != 0) 173 out.writeByte(jmsSystemMsgType); 174 } 175 176 179 void unmarshal(DataInput in) throws IOException 180 { 181 182 bitMask = in.readShort(); 183 184 if ((bitMask & JMS_DESTINATION) != 0) 185 jmsDestination = in.readUTF(); 186 187 if ((bitMask & JMS_MESSAGEID) != 0) 188 jmsMessageID = MessageID.unmarshal(in); 189 190 if ((bitMask & JMS_DELIVERYMODE) != 0) 191 jmsDeliveryMode = in.readByte(); 192 193 if ((bitMask & JMS_CORRELATION) != 0) 194 jmsCorrelationID = MessageID.unmarshal(in); 195 196 if ((bitMask & JMS_EXPIRATION) != 0) 197 jmsExpiration = in.readLong(); 198 199 if ((bitMask & JMS_TIMESTAMP) != 0) 200 jmsTimestamp = in.readLong(); 201 202 if ((bitMask & JMS_PRIORITY) != 0) 203 jmsPriority = in.readByte(); 204 205 if ((bitMask & JMS_REPLYTO) != 0) 206 jmsReplyTo = in.readUTF(); 207 208 if ((bitMask & JMS_REDELIV) != 0) 209 jmsRedelivered = in.readBoolean(); 210 211 if ((bitMask & JMS_TYPE) != 0) 212 jmsType = in.readUTF(); 213 214 if ((bitMask & JMS_SYSTEM_TYPE) != 0) 215 jmsSystemMsgType = in.readByte(); 216 } 217 218 219 final void setJMSMessageID(MessageID messageID) 220 { 221 jmsMessageID = messageID; 222 bitMask |= JMS_MESSAGEID; 223 } 224 225 final void setJMSTimestamp(long timestamp) 226 { 227 jmsTimestamp = timestamp; 228 bitMask |= JMS_TIMESTAMP; 229 } 230 231 final void setJMSCorrelationID(MessageID correlationID) 232 { 233 jmsCorrelationID = correlationID; 234 bitMask |= JMS_CORRELATION; 235 } 236 237 final void setJMSReplyTo(Destination replyTo) 238 { 239 jmsReplyTo = replyTo.toString(); 240 bitMask |= JMS_REPLYTO; 241 } 242 243 final void setJMSDestination(Destination destination) 244 { 245 jmsDestination = destination.toString(); 246 bitMask |= JMS_DESTINATION; 247 } 248 249 final void setJMSDeliveryMode(int deliveryMode) 250 { 251 jmsDeliveryMode = deliveryMode; 252 bitMask |= JMS_DELIVERYMODE; 253 } 254 255 final void setJMSRedelivered(boolean redelivered) 256 { 257 jmsRedelivered = redelivered; 258 bitMask |= JMS_REDELIV; 259 } 260 261 final void setJMSType(String type) 262 { 263 jmsType = type; 264 bitMask |= JMS_TYPE; 265 } 266 267 final void setJMSExpiration(long expiration) 268 { 269 jmsExpiration = expiration; 270 bitMask |= JMS_EXPIRATION; 271 } 272 273 final void setJMSPriority(int priority) 274 { 275 jmsPriority = priority; 276 bitMask |= JMS_PRIORITY; 277 } 278 279 final void setJMSSystemMsgType(int type) 280 { 281 jmsSystemMsgType = type; 282 bitMask |= JMS_SYSTEM_TYPE; 283 284 if (type == SystemMessageConstants.DEFAULT) 285 bitMask ^= JMS_SYSTEM_TYPE; 286 } 287 } 288 | Popular Tags |