1 45 package org.exolab.jms.messagemgr; 46 47 import java.sql.Connection ; 48 import javax.jms.JMSException ; 49 import javax.jms.MessageConsumer ; 50 51 import org.exolab.jms.client.JmsDestination; 52 import org.exolab.jms.message.MessageImpl; 53 import org.exolab.jms.persistence.PersistenceException; 54 import org.exolab.jms.server.ServerConnection; 55 56 57 63 public abstract class AbstractMessageHandle implements MessageHandle { 64 65 68 private MessageRef _reference; 69 70 73 private final String _messageId; 74 75 79 private boolean _delivered = false; 80 81 84 private final int _priority; 85 86 89 private long _acceptedTime; 90 91 96 private final long _sequenceNumber; 97 98 101 private long _expiryTime; 102 103 106 private final JmsDestination _destination; 107 108 112 private final long _consumerId; 113 114 118 private final long _connectionId; 119 120 121 128 public AbstractMessageHandle(MessageRef reference, MessageImpl message) 129 throws JMSException { 130 if (reference == null) { 131 throw new IllegalArgumentException ("Argument 'reference' is null"); 132 } 133 if (message == null) { 134 throw new IllegalArgumentException ("Argument 'message' is null"); 135 } 136 _messageId = message.getMessageId().getId(); 137 _delivered = message.getJMSRedelivered(); 138 _priority = message.getJMSPriority(); 139 _acceptedTime = message.getAcceptedTime(); 140 _sequenceNumber = message.getSequenceNumber(); 141 _expiryTime = message.getJMSExpiration(); 142 _destination = (JmsDestination) message.getJMSDestination(); 143 _consumerId = message.getConsumerId(); 144 _connectionId = message.getConnectionId(); 145 _reference = reference; 146 } 147 148 157 public AbstractMessageHandle(String messageId, int priority, 158 long acceptedTime, long sequenceNumber, 159 long expiryTime, JmsDestination destination) { 160 if (messageId == null) { 161 throw new IllegalArgumentException ("Argument 'messageId' is null"); 162 } 163 if (destination == null) { 164 throw new IllegalArgumentException ( 165 "Argument 'destination' is null"); 166 } 167 _messageId = messageId; 168 _priority = priority; 169 _acceptedTime = acceptedTime; 170 _sequenceNumber = sequenceNumber; 171 _expiryTime = expiryTime; 172 _destination = destination; 173 _consumerId = -1; 174 _connectionId = -1; 175 } 176 177 182 public String getMessageId() { 183 return _messageId; 184 } 185 186 193 public MessageImpl getMessage() throws JMSException { 194 if (_reference == null) { 195 throw new JMSException ("Cannot get message with identifier=" 196 + _messageId + ": MessageRef null"); 197 } 198 return _reference.getMessage(); 199 } 200 201 202 209 public void setDelivered(boolean delivered) { 210 _delivered = delivered; 211 } 212 213 218 public boolean getDelivered() { 219 return _delivered; 220 } 221 222 227 public int getPriority() { 228 return _priority; 229 } 230 231 237 public long getAcceptedTime() { 238 return _acceptedTime; 239 } 240 241 246 public long getExpiryTime() { 247 return _expiryTime; 248 } 249 250 256 public boolean hasExpired() { 257 return (_expiryTime != 0 && _expiryTime <= System.currentTimeMillis()); 258 } 259 260 265 public long getSequenceNumber() { 266 return _sequenceNumber; 267 } 268 269 274 public JmsDestination getDestination() { 275 return _destination; 276 } 277 278 284 public long getConsumerId() { 285 return _consumerId; 286 } 287 288 295 public String getConsumerPersistentId() { 296 return null; 297 } 298 299 305 public long getConnectionId() { 306 return _connectionId; 307 } 308 309 314 public boolean isPersistent() { 315 return false; 316 } 317 318 325 public boolean equals(Object object) { 326 boolean result = (object instanceof MessageHandle); 327 if (result) { 328 result = _messageId.equals(((MessageHandle) object).getMessageId()); 329 } 330 return result; 331 } 332 333 338 public int hashCode() { 339 return _messageId.hashCode(); 340 } 341 342 347 public String toString() { 348 return "MessageHandle : " + _priority + ":" + getAcceptedTime() + 349 ":" + getSequenceNumber() + ":" + _messageId; 350 } 351 352 358 public void destroy() throws JMSException { 359 getMessageRef().dereference(); 360 } 361 362 370 public void destroy(Connection connection) throws JMSException , 371 PersistenceException { 372 getMessageRef().dereference(); 373 } 374 375 380 public MessageRef getMessageRef() { 381 return _reference; 382 } 383 384 389 protected void setMessageRef(MessageRef reference) { 390 _reference = reference; 391 } 392 393 } 394 | Popular Tags |