1 7 package org.jboss.jms.client; 8 9 import javax.jms.Destination ; 10 import javax.jms.JMSException ; 11 import javax.jms.Message ; 12 import javax.jms.MessageProducer ; 13 import javax.jms.Queue ; 14 import javax.jms.QueueSender ; 15 import javax.jms.Topic ; 16 import javax.jms.TopicPublisher ; 17 18 import org.jboss.jms.JMSValidator; 19 import org.jboss.jms.message.JBossMessage; 20 21 27 public class JBossProducer 28 implements MessageProducer , QueueSender , TopicPublisher 29 { 30 32 34 35 private ProducerDelegate delegate; 36 37 38 private Destination defaultDestination; 39 40 41 private int defaultDeliveryMode = Message.DEFAULT_DELIVERY_MODE; 42 43 44 private int defaultPriority = Message.DEFAULT_PRIORITY; 45 46 47 private long defaultTimeToLive = Message.DEFAULT_TIME_TO_LIVE; 48 49 50 private boolean disableMessageID = false; 51 52 53 private boolean disableTimestamp = false; 54 55 57 59 66 public JBossProducer(ProducerDelegate delegate, Destination destination) 67 throws JMSException 68 { 69 this.delegate = delegate; 70 this.defaultDestination = destination; 71 } 72 73 75 77 public void close() throws JMSException 78 { 79 delegate.closing(); 80 delegate.close(); 81 } 82 83 public int getDeliveryMode() throws JMSException 84 { 85 return defaultDeliveryMode; 86 } 87 88 public Destination getDestination() throws JMSException 89 { 90 return defaultDestination; 91 } 92 93 public boolean getDisableMessageID() throws JMSException 94 { 95 return disableMessageID; 96 } 97 98 public boolean getDisableMessageTimestamp() throws JMSException 99 { 100 return disableTimestamp; 101 } 102 103 public int getPriority() throws JMSException 104 { 105 return defaultPriority; 106 } 107 108 public long getTimeToLive() throws JMSException 109 { 110 return defaultTimeToLive; 111 } 112 113 public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) 114 throws JMSException 115 { 116 if (destination == null) 117 throw new JMSException ("Null destination"); 118 if (message == null) 119 throw new JMSException ("Null message"); 120 JMSValidator.validateDeliveryMode(deliveryMode); 121 JMSValidator.validatePriority(priority); 122 JMSValidator.validateTimeToLive(timeToLive); 123 124 JBossMessage msg; 125 if ((message instanceof JBossMessage)) 126 msg = (JBossMessage) message; 127 else 128 msg = delegate.encapsulateMessage(message); 129 130 if (disableMessageID == false) 131 msg.generateMessageID(); 132 133 if (disableTimestamp == false) 134 msg.generateTimestamp(); 135 136 msg.setJMSDestination(destination); 137 msg.setJMSDeliveryMode(deliveryMode); 138 msg.setJMSPriority(priority); 139 if (disableTimestamp == false && timeToLive != 0) 140 msg.setJMSExpiration(msg.getJMSTimestamp() + timeToLive); 141 142 delegate.send(msg); 143 } 144 145 public void send(Destination destination, Message message) throws JMSException 146 { 147 send(destination, message, defaultDeliveryMode, defaultPriority, defaultTimeToLive); 148 } 149 150 public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException 151 { 152 send(defaultDestination, message, deliveryMode, priority, timeToLive); 153 } 154 155 public void send(Message message) throws JMSException 156 { 157 send(defaultDestination, message, defaultDeliveryMode, defaultPriority, defaultTimeToLive); 158 } 159 160 public void setDeliveryMode(int deliveryMode) throws JMSException 161 { 162 JMSValidator.validateDeliveryMode(deliveryMode); 163 this.defaultDeliveryMode = deliveryMode; 164 } 165 166 public void setDisableMessageID(boolean value) throws JMSException 167 { 168 this.disableMessageID = value; 169 } 170 171 public void setDisableMessageTimestamp(boolean value) throws JMSException 172 { 173 this.disableTimestamp = value; 174 } 175 176 public void setPriority(int defaultPriority) throws JMSException 177 { 178 JMSValidator.validatePriority(defaultPriority); 179 this.defaultPriority = defaultPriority; 180 } 181 182 public void setTimeToLive(long timeToLive) throws JMSException 183 { 184 JMSValidator.validateTimeToLive(timeToLive); 185 this.defaultTimeToLive = timeToLive; 186 } 187 188 190 public Queue getQueue() throws JMSException 191 { 192 return (Queue ) getDestination(); 193 } 194 195 public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException 196 { 197 send(queue, message, deliveryMode, priority, timeToLive); 198 } 199 200 public void send(Queue queue, Message message) throws JMSException 201 { 202 send(queue, message); 203 } 204 205 207 public Topic getTopic() throws JMSException 208 { 209 return (Topic ) getDestination(); 210 } 211 212 public void publish(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException 213 { 214 send(defaultDestination, message, deliveryMode, priority, timeToLive); 215 } 216 217 public void publish(Message message) throws JMSException 218 { 219 send(message); 220 } 221 222 public void publish(Topic topic, Message message, int deliveryMode, int priority, long timeToLive) 223 throws JMSException 224 { 225 send(topic, message, deliveryMode, priority, timeToLive); 226 } 227 228 public void publish(Topic topic, Message message) throws JMSException 229 { 230 send(topic, message); 231 } 232 233 235 237 239 241 } 242 | Popular Tags |