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.codehaus.activemq.service.impl;
20
21 import org.codehaus.activemq.message.MessageAck;
22 import org.codehaus.activemq.service.MessageContainer;
23 import org.codehaus.activemq.service.MessageIdentity;
24
25 import javax.jms.JMSException;
26
27
28 /***
29 * An entry for a message to be dispatched
30 *
31 * @version $Revision: 1.3 $
32 */
33 class MessagePointer {
34 private MessageContainer container;
35 private MessageIdentity messageIdentity;
36 private boolean dispatched;
37 private boolean read;
38
39
40 /***
41 * Create a message ptr
42 *
43 * @param container the container where the message is held
44 * @param messageIdentity the id of the message
45 * @throws JMSException
46 */
47
48 public MessagePointer(MessageContainer container, MessageIdentity messageIdentity) throws JMSException {
49 this.container = container;
50 this.messageIdentity = messageIdentity;
51 this.container.registerMessageInterest(this.messageIdentity);
52 }
53
54
55 /***
56 * Reset default states for this MessagePointer
57 */
58
59 public void reset() {
60 this.dispatched = false;
61 this.read = false;
62 }
63
64 /***
65 * Simply remove the interest in the message
66 *
67 * @throws JMSException
68 */
69
70 public void clear() throws JMSException {
71 container.unregisterMessageInterest(messageIdentity, null);
72 }
73
74
75 /***
76 * Notify the container it should delete the message
77 *
78 * @param ack
79 * @throws JMSException
80 */
81
82 public void delete(MessageAck ack) throws JMSException {
83 clear();
84 container.delete(messageIdentity, ack);
85 }
86
87 /***
88 * @return Returns the container.
89 */
90 public MessageContainer getContainer() {
91 return container;
92 }
93
94 /***
95 * @param container The container to set.
96 */
97 public void setContainer(MessageContainer container) {
98 this.container = container;
99 }
100
101 /***
102 * @return Returns the dispatched.
103 */
104 public boolean isDispatched() {
105 return dispatched;
106 }
107
108 /***
109 * @param dispatched The dispatched to set.
110 */
111 public void setDispatched(boolean dispatched) {
112 this.dispatched = dispatched;
113 }
114
115 /***
116 * @return Returns the read.
117 */
118 public boolean isRead() {
119 return read;
120 }
121
122 /***
123 * @param read The read to set.
124 */
125 public void setRead(boolean read) {
126 this.read = read;
127 }
128
129 public MessageIdentity getMessageIdentity() {
130 return messageIdentity;
131 }
132
133 public void setMessageIdentity(MessageIdentity messageIdentity) {
134 this.messageIdentity = messageIdentity;
135 }
136 }