1 28 29 package com.caucho.jms.session; 30 31 import com.caucho.jms.AbstractDestination; 32 import com.caucho.jms.message.MessageImpl; 33 import com.caucho.util.Alarm; 34 import com.caucho.util.L10N; 35 36 import javax.jms.DeliveryMode ; 37 import javax.jms.Destination ; 38 import javax.jms.JMSException ; 39 import javax.jms.Message ; 40 import javax.jms.MessageProducer ; 41 42 45 public class MessageProducerImpl implements MessageProducer { 46 static final L10N L = new L10N(MessageProducer .class); 47 48 private int _deliveryMode = DeliveryMode.NON_PERSISTENT; 49 private boolean _disableMessageId = true; 50 private boolean _disableMessageTimestamp = true; 51 private int _priority = 4; 52 private long _timeToLive = 30 * 24 * 3600 * 1000L; 53 54 protected SessionImpl _session; 55 protected AbstractDestination _destination; 56 57 public MessageProducerImpl(SessionImpl session, Destination destination) 58 { 59 _session = session; 60 _destination = (AbstractDestination) destination; 61 } 62 63 66 public Destination getDestination() 67 { 68 return _destination; 69 } 70 71 74 public int getDeliveryMode() 75 { 76 return _deliveryMode; 77 } 78 79 82 public void setDeliveryMode(int deliveryMode) 83 { 84 _deliveryMode = deliveryMode; 85 } 86 87 90 public boolean getDisableMessageID() 91 { 92 return _disableMessageId; 93 } 94 95 98 public void setDisableMessageID(boolean disable) 99 { 100 _disableMessageId = disable; 101 } 102 103 106 public boolean getDisableMessageTimestamp() 107 { 108 return _disableMessageTimestamp; 109 } 110 111 114 public void setDisableMessageTimestamp(boolean disable) 115 { 116 _disableMessageTimestamp = disable; 117 } 118 119 122 public int getPriority() 123 { 124 return _priority; 125 } 126 127 130 public void setPriority(int priority) 131 { 132 _priority = priority; 133 } 134 135 138 public long getTimeToLive() 139 { 140 return _timeToLive; 141 } 142 143 146 public void setTimeToLive(long timeToLive) 147 { 148 _timeToLive = timeToLive; 149 } 150 151 156 public void send(Message message) 157 throws JMSException 158 { 159 send(_destination, message, 160 _deliveryMode, _priority, _timeToLive); 161 } 162 163 171 public void send(Message message, 172 int deliveryMode, 173 int priority, 174 long timeToLive) 175 throws JMSException 176 { 177 send(_destination, message, 178 deliveryMode, priority, timeToLive); 179 } 180 181 187 public void send(Destination destination, Message message) 188 throws JMSException 189 { 190 send(destination, message, 191 _deliveryMode, _priority, _timeToLive); 192 } 193 194 203 public void send(Destination destination, 204 Message message, 205 int deliveryMode, 206 int priority, 207 long timeToLive) 208 throws JMSException 209 { 210 _session.send((AbstractDestination) destination, 211 (MessageImpl) message, 212 deliveryMode, priority, 213 calculateExpiration(timeToLive)); 214 } 216 217 220 protected long calculateExpiration(long timeToLive) 221 { 222 if (timeToLive <= 0) 223 return timeToLive; 224 else 225 return timeToLive + Alarm.getCurrentTime(); 226 } 227 228 231 public void close() 232 throws JMSException 233 { 234 } 235 } 236 237 | Popular Tags |