1 24 package org.objectweb.joram.client.jms; 25 26 import javax.jms.IllegalStateException ; 27 import javax.jms.MessageFormatException ; 28 import javax.jms.JMSException ; 29 30 import org.objectweb.joram.shared.client.*; 31 32 import org.objectweb.util.monolog.api.BasicLevel; 33 import org.objectweb.joram.shared.JoramTracing; 34 35 38 public class MessageProducer implements javax.jms.MessageProducer { 39 40 private int deliveryMode = javax.jms.DeliveryMode.PERSISTENT; 41 42 43 private int priority = 4; 44 45 46 private long timeToLive = 0; 47 48 53 private boolean messageIDDisabled = false; 54 55 56 private boolean timestampDisabled = false; 57 58 59 private boolean identified = true; 60 61 62 protected boolean closed = false; 63 64 65 protected Session sess; 66 67 68 protected Destination dest = null; 69 70 79 MessageProducer(Session sess, 80 Destination dest) 81 throws JMSException { 82 this.sess = sess; 83 this.dest = dest; 84 if (dest == null) 85 identified = false; 86 87 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 88 JoramTracing.dbgClient.log(BasicLevel.DEBUG, this + ": created."); 89 } 90 91 96 public synchronized void setDisableMessageID(boolean value) throws JMSException 97 { 98 if (closed) 99 throw new IllegalStateException ("Forbidden call on a closed producer."); 100 } 101 102 109 public synchronized void setDeliveryMode(int deliveryMode) throws JMSException 110 { 111 if (closed) 112 throw new IllegalStateException ("Forbidden call on a closed producer."); 113 114 if (deliveryMode != javax.jms.DeliveryMode.PERSISTENT 115 && deliveryMode != javax.jms.DeliveryMode.NON_PERSISTENT) 116 throw new JMSException ("Can't set invalid delivery mode."); 117 118 this.deliveryMode = deliveryMode; 119 } 120 121 128 public synchronized void setPriority(int priority) throws JMSException 129 { 130 if (closed) 131 throw new IllegalStateException ("Forbidden call on a closed producer."); 132 133 if (priority < 0 || priority > 9) 134 throw new JMSException ("Can't set invalid priority value."); 135 136 this.priority = priority; 137 } 138 139 146 public synchronized void setTimeToLive(long timeToLive) throws JMSException 147 { 148 if (closed) 149 throw new IllegalStateException ("Forbidden call on a closed producer."); 150 151 this.timeToLive = timeToLive; 152 } 153 154 159 public synchronized void setDisableMessageTimestamp(boolean value) throws JMSException 160 { 161 if (closed) 162 throw new IllegalStateException ("Forbidden call on a closed producer."); 163 164 this.timestampDisabled = value; 165 } 166 167 173 public synchronized javax.jms.Destination getDestination() throws JMSException 174 { 175 if (closed) 176 throw new IllegalStateException ("Forbidden call on a closed producer."); 177 178 return dest; 179 } 180 181 186 public synchronized boolean getDisableMessageID() throws JMSException 187 { 188 if (closed) 189 throw new IllegalStateException ("Forbidden call on a closed producer."); 190 191 return messageIDDisabled; 192 } 193 194 200 public synchronized int getDeliveryMode() throws JMSException 201 { 202 if (closed) 203 throw new IllegalStateException ("Forbidden call on a closed producer."); 204 205 return deliveryMode; 206 } 207 208 214 public synchronized int getPriority() throws JMSException 215 { 216 if (closed) 217 throw new IllegalStateException ("Forbidden call on a closed producer."); 218 219 return priority; 220 } 221 222 229 public synchronized long getTimeToLive() throws JMSException 230 { 231 if (closed) 232 throw new IllegalStateException ("Forbidden call on a closed producer."); 233 234 return timeToLive; 235 } 236 237 242 public synchronized boolean getDisableMessageTimestamp() throws JMSException 243 { 244 if (closed) 245 throw new IllegalStateException ("Forbidden call on a closed producer."); 246 247 return timestampDisabled; 248 } 249 250 251 259 public synchronized void send(javax.jms.Message message) throws JMSException 260 { 261 if (! identified) 262 throw new UnsupportedOperationException ("Can't send message to" 263 + " an unidentified" 264 + " destination."); 265 doSend(dest, message, deliveryMode, priority, timeToLive); 267 } 268 269 277 public synchronized void send(javax.jms.Message message, 278 int deliveryMode, 279 int priority, 280 long timeToLive) throws JMSException 281 { 282 if (! identified) 283 throw new UnsupportedOperationException ("Can't send message to" 284 + " an unidentified" 285 + " destination."); 286 doSend(dest, message, deliveryMode, priority, timeToLive); 288 } 289 290 302 public synchronized void send(javax.jms.Destination dest, 303 javax.jms.Message message) throws JMSException 304 { 305 if (identified) 306 throw new UnsupportedOperationException ("An unidentified message" 307 + " producer can't use this" 308 + " identified message" 309 + " producer."); 310 if (dest == null) 311 throw new UnsupportedOperationException ("Can't send message to" 312 + " an unidentified" 313 + " destination."); 314 315 doSend((Destination) dest, message, deliveryMode, priority, timeToLive); 316 } 317 318 330 public synchronized void send(javax.jms.Destination dest, 331 javax.jms.Message message, 332 int deliveryMode, 333 int priority, 334 long timeToLive) throws JMSException 335 { 336 if (identified) 337 throw new UnsupportedOperationException ("An unidentified message" 338 + " producer can't use this" 339 + " identified message" 340 + " producer."); 341 if (dest == null) 342 throw new UnsupportedOperationException ("Can't send message to" 343 + " an unidentified" 344 + " destination."); 345 346 doSend((Destination) dest, message, deliveryMode, priority, timeToLive); 347 } 348 349 355 public synchronized void close() throws JMSException 356 { 357 if (closed) 359 return; 360 361 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 362 JoramTracing.dbgClient.log(BasicLevel.DEBUG, "--- " + this 363 + ": closing..."); 364 365 sess.closeProducer(this); 366 closed = true; 367 368 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 369 JoramTracing.dbgClient.log(BasicLevel.DEBUG, this + ": closed."); 370 371 } 372 373 382 private void doSend(Destination dest, 383 javax.jms.Message message, 384 int deliveryMode, 385 int priority, 386 long timeToLive) 387 throws JMSException { 388 if (closed) 389 throw new IllegalStateException ("Forbidden call on a closed producer."); 390 391 sess.send(dest, message, deliveryMode, priority, 392 timeToLive, timestampDisabled); 393 } 394 } 395 | Popular Tags |