Source code: org/activemq/service/impl/MessagePointer.java
1 /**
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18
19 package org.activemq.service.impl;
20
21 import org.activemq.message.ActiveMQMessage;
22 import org.activemq.message.MessageAck;
23 import org.activemq.service.MessageContainer;
24 import org.activemq.service.MessageIdentity;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import javax.jms.JMSException;
29
30
31 /**
32 * An entry for a message to be dispatched
33 *
34 * @version $Revision: 1.1.1.1 $
35 */
36 class MessagePointer {
37 private static final Log log = LogFactory.getLog(MessagePointer.class);
38
39 private MessageContainer container;
40 private MessageIdentity messageIdentity;
41 private boolean dispatched;
42 private boolean read;
43 private boolean redelivered;
44 private boolean deleted;
45
46
47 public MessagePointer(MessagePointer copy) throws JMSException {
48 this.container = copy.container;
49 this.messageIdentity = copy.messageIdentity;
50 this.container.registerMessageInterest(this.messageIdentity);
51 }
52
53 /**
54 * Create a message ptr
55 *
56 * @param container the container where the message is held
57 * @param message the message to point to
58 * @throws JMSException
59 */
60
61 public MessagePointer(MessageContainer container, ActiveMQMessage message) throws JMSException {
62 this.container = container;
63 this.messageIdentity = message.getJMSMessageIdentity();
64 this.redelivered = message.getJMSRedelivered();
65 this.container.registerMessageInterest(this.messageIdentity);
66 }
67
68 /**
69 * Reset default states for this MessagePointer
70 */
71
72 public void reset() {
73 this.dispatched = false;
74 this.read = false;
75 this.deleted=false;
76 }
77
78 /**
79 * Simply remove the interest in the message
80 *
81 * @throws JMSException
82 */
83
84 public void clear() throws JMSException {
85 container.unregisterMessageInterest(messageIdentity);
86 }
87
88
89 /**
90 * Notify the container it should delete the message
91 *
92 * @param ack
93 * @throws JMSException
94 */
95
96 public void delete(MessageAck ack) throws JMSException {
97 clear();
98 deleted=true;
99 container.delete(messageIdentity, ack);
100 }
101
102 /**
103 * @return Returns the container.
104 */
105 public MessageContainer getContainer() {
106 return container;
107 }
108
109 /**
110 * @param container The container to set.
111 */
112 public void setContainer(MessageContainer container) {
113 this.container = container;
114 }
115
116 /**
117 * @return Returns the dispatched.
118 */
119 public boolean isDispatched() {
120 return dispatched;
121 }
122
123 /**
124 * @return Returns the deleted.
125 */
126 public boolean isDeleted() {
127 return deleted;
128 }
129
130 /**
131 * @param dispatched The dispatched to set.
132 */
133 public void setDispatched(boolean dispatched) {
134 this.dispatched = dispatched;
135 }
136
137 /**
138 * @return Returns the read.
139 */
140 public boolean isRead() {
141 return read;
142 }
143
144 /**
145 * @param read The read to set.
146 */
147 public void setRead(boolean read) {
148 this.read = read;
149 }
150
151 public MessageIdentity getMessageIdentity() {
152 return messageIdentity;
153 }
154
155 public void setMessageIdentity(MessageIdentity messageIdentity) {
156 this.messageIdentity = messageIdentity;
157 }
158 /**
159 * @return Returns the redilivered.
160 */
161 public boolean isRedelivered() {
162 return redelivered;
163 }
164 /**
165 * @param redelivered The redilivered to set.
166 * @throws JMSException
167 */
168 public void setRedelivered(boolean redelivered) throws JMSException {
169 if( !deleted ) {
170 this.redelivered = redelivered;
171 ActiveMQMessage message = getContainer().getMessage(getMessageIdentity());
172 if (message == null) {
173 log.warn("Could not find message: " + getMessageIdentity() + " when trying to set redelivered to: " + redelivered);
174 }
175 else {
176 message.setJMSRedelivered(redelivered);
177 }
178 }
179 }
180 }