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.message;
20
21 import org.codehaus.activemq.service.MessageIdentity;
22
23 /***
24 * Denotes an object that can be serialized/deserailized using a PacketReader/PacketWriter
25 */
26
27 public class MessageAck extends AbstractPacket {
28
29 static final int MESSAGE_READ_INDEX = 0;
30 static final int XA_TRANSACTED_INDEX = 1;
31 static final int PERSISTENT_INDEX = 2;
32 private String consumerId;
33 private String messageID;
34 private ActiveMQDestination destination;
35 private String transactionId;
36 private boolean messageRead;
37 private boolean xaTransacted;
38 private boolean persistent;
39 private transient MessageIdentity messageIdentity;
40
41
42 /***
43 * Return the type of Packet
44 *
45 * @return integer representation of the type of Packet
46 */
47
48 public int getPacketType() {
49 return ACTIVEMQ_MSG_ACK;
50 }
51
52 /***
53 * @return pretty print of this Packet
54 */
55 public String toString() {
56 String str = super.toString();
57 str += " consumerId = " + consumerId;
58 str += " , messageId = " + messageID;
59 str += " ,read = " + messageRead;
60 str += " ,trans = " + transactionId;
61 return str;
62 }
63
64
65 /***
66 * @return Returns the transactionId.
67 */
68 public String getTransactionId() {
69 return this.transactionId;
70 }
71
72 /***
73 * @param newTransactionId The transactionId to set.
74 */
75 public void setTransactionId(String newTransactionId) {
76 this.transactionId = newTransactionId;
77 }
78
79 /***
80 * @return Returns true if this message is part of a transaction
81 */
82
83 public boolean isPartOfTransaction() {
84 return this.transactionId != null && this.transactionId.length() > 0;
85 }
86
87
88 /***
89 * @return Returns the messageID.
90 */
91 public String getMessageID() {
92 return messageID;
93 }
94
95 /***
96 * @param messageID The messageID to set.
97 */
98 public void setMessageID(String messageID) {
99 this.messageID = messageID;
100 }
101
102 /***
103 * @return Returns the messageRead.
104 */
105 public boolean isMessageRead() {
106 return messageRead;
107 }
108
109 /***
110 * @param messageRead The messageRead to set.
111 */
112 public void setMessageRead(boolean messageRead) {
113 this.messageRead = messageRead;
114 }
115
116 /***
117 * @return Returns the consumerId.
118 */
119 public String getConsumerId() {
120 return consumerId;
121 }
122
123 /***
124 * @param consumerId The consumerId to set.
125 */
126 public void setConsumerId(String consumerId) {
127 this.consumerId = consumerId;
128 }
129
130 /***
131 * @return Returns the xaTransacted.
132 */
133 public boolean isXaTransacted() {
134 return xaTransacted;
135 }
136
137 /***
138 * @param xaTransacted The xaTransacted to set.
139 */
140 public void setXaTransacted(boolean xaTransacted) {
141 this.xaTransacted = xaTransacted;
142 }
143
144 public MessageIdentity getMessageIdentity() {
145 if (messageIdentity == null) {
146 messageIdentity = new MessageIdentity(messageID);
147 }
148 return messageIdentity;
149 }
150 /***
151 * @return Returns the destination.
152 */
153 public ActiveMQDestination getDestination() {
154 return destination;
155 }
156 /***
157 * @param destination The destination to set.
158 */
159 public void setDestination(ActiveMQDestination destination) {
160 this.destination = destination;
161 }
162 /***
163 * @return Returns the persistent.
164 */
165 public boolean isPersistent() {
166 return persistent;
167 }
168 /***
169 * @param persistent The persistent to set.
170 */
171 public void setPersistent(boolean persistent) {
172 this.persistent = persistent;
173 }
174
175 /***
176 * @return true the delivered message was to a non-persistent destination
177 */
178 public boolean isTemporary(){
179 return persistent == false || (destination != null && destination.isTemporary());
180 }
181 }