1 45 46 package org.exolab.jms.messagemgr; 47 48 import java.sql.Connection ; 49 import javax.jms.JMSException ; 50 import javax.jms.MessageConsumer ; 51 52 import org.exolab.jms.client.JmsDestination; 53 import org.exolab.jms.message.MessageImpl; 54 import org.exolab.jms.persistence.DatabaseService; 55 import org.exolab.jms.persistence.PersistenceException; 56 57 58 64 abstract class AbstractConsumerMessageHandle implements MessageHandle { 65 66 69 private final MessageHandle _handle; 70 71 74 private long _consumerId; 75 76 79 private final String _persistentId; 80 81 84 private boolean _persistent; 85 86 87 94 public AbstractConsumerMessageHandle(MessageHandle handle, 95 ConsumerEndpoint consumer) 96 throws JMSException { 97 this(handle, consumer.getId(), consumer.getPersistentId()); 98 } 99 100 108 public AbstractConsumerMessageHandle(MessageHandle handle, 109 String persistentId) 110 throws JMSException { 111 this(handle, -1L, persistentId); 112 } 113 114 123 protected AbstractConsumerMessageHandle(MessageHandle handle, long consumerId, 124 String persistentId) 125 throws JMSException { 126 if (handle == null) { 127 throw new IllegalArgumentException ("Argument 'handle' is null"); 128 } 129 _handle = handle; 130 _consumerId = consumerId; 131 _persistentId = persistentId; 132 _handle.getMessageRef().reference(); 133 } 134 135 140 public String getMessageId() { 141 return _handle.getMessageId(); 142 } 143 144 151 public void setDelivered(boolean delivered) { 152 _handle.setDelivered(delivered); 153 } 154 155 160 public boolean getDelivered() { 161 return _handle.getDelivered(); 162 } 163 164 169 public int getPriority() { 170 return _handle.getPriority(); 171 } 172 173 179 public long getAcceptedTime() { 180 return _handle.getAcceptedTime(); 181 } 182 183 188 public long getExpiryTime() { 189 return _handle.getExpiryTime(); 190 } 191 192 198 public boolean hasExpired() { 199 return _handle.hasExpired(); 200 } 201 202 207 public long getSequenceNumber() { 208 return _handle.getSequenceNumber(); 209 } 210 211 216 public JmsDestination getDestination() { 217 return _handle.getDestination(); 218 } 219 220 226 public long getConsumerId() { 227 return _consumerId; 228 } 229 230 237 public String getConsumerPersistentId() { 238 return _persistentId; 239 } 240 241 248 public long getConnectionId() { 249 return _handle.getConnectionId(); 250 } 251 252 258 public boolean isPersistent() { 259 return _persistent; 260 } 261 262 269 public MessageImpl getMessage() throws JMSException { 270 return _handle.getMessage(); 271 } 272 273 279 public void add(Connection connection) throws PersistenceException { 280 DatabaseService.getAdapter().addMessageHandle(connection, this); 281 _persistent = true; 282 } 283 284 290 public void update(Connection connection) throws PersistenceException { 291 DatabaseService.getAdapter().updateMessageHandle(connection, this); 292 } 293 294 300 public void destroy() throws JMSException { 301 _handle.destroy(); 302 } 303 304 312 public void destroy(Connection connection) throws JMSException , 313 PersistenceException { 314 DatabaseService.getAdapter().removeMessageHandle(connection, this); 315 _handle.destroy(connection); 316 _persistent = false; 317 } 318 319 324 public MessageRef getMessageRef() { 325 return _handle.getMessageRef(); 326 } 327 328 333 protected void setConsumerId(long consumerId) { 334 _consumerId = consumerId; 335 } 336 337 343 protected void setPersistent(boolean persistent) { 344 _persistent = persistent; 345 } 346 347 } 348 349 | Popular Tags |