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 private String consumerId;
30 private String messageID;
31 private String transactionId;
32 private boolean messageRead;
33 private boolean xaTransacted;
34 private transient MessageIdentity messageIdentity;
35
36
37 /***
38 * Return the type of Packet
39 *
40 * @return integer representation of the type of Packet
41 */
42
43 public int getPacketType() {
44 return ACTIVEMQ_MSG_ACK;
45 }
46
47 /***
48 * @return pretty print of this Packet
49 */
50 public String toString() {
51 String str = super.toString();
52 str += " consumerId = " + consumerId;
53 str += " , messageId = " + messageID;
54 str += " ,read = " + messageRead;
55 str += " ,trans = " + transactionId;
56 return str;
57 }
58
59
60 /***
61 * @return Returns the transactionId.
62 */
63 public String getTransactionId() {
64 return this.transactionId;
65 }
66
67 /***
68 * @param newTransactionId The transactionId to set.
69 */
70 public void setTransactionId(String newTransactionId) {
71 this.transactionId = newTransactionId;
72 }
73
74 /***
75 * @return Returns true if this message is part of a transaction
76 */
77
78 public boolean isPartOfTransaction() {
79 return this.transactionId != null && this.transactionId.length() > 0;
80 }
81
82
83 /***
84 * @return Returns the messageID.
85 */
86 public String getMessageID() {
87 return messageID;
88 }
89
90 /***
91 * @param messageID The messageID to set.
92 */
93 public void setMessageID(String messageID) {
94 this.messageID = messageID;
95 }
96
97 /***
98 * @return Returns the messageRead.
99 */
100 public boolean isMessageRead() {
101 return messageRead;
102 }
103
104 /***
105 * @param messageRead The messageRead to set.
106 */
107 public void setMessageRead(boolean messageRead) {
108 this.messageRead = messageRead;
109 }
110
111 /***
112 * @return Returns the consumerId.
113 */
114 public String getConsumerId() {
115 return consumerId;
116 }
117
118 /***
119 * @param consumerId The consumerId to set.
120 */
121 public void setConsumerId(String consumerId) {
122 this.consumerId = consumerId;
123 }
124
125 /***
126 * @return Returns the xaTransacted.
127 */
128 public boolean isXaTransacted() {
129 return xaTransacted;
130 }
131
132 /***
133 * @param xaTransacted The xaTransacted to set.
134 */
135 public void setXaTransacted(boolean xaTransacted) {
136 this.xaTransacted = xaTransacted;
137 }
138
139 public MessageIdentity getMessageIdentity() {
140 if (messageIdentity == null) {
141 messageIdentity = new MessageIdentity(messageID);
142 }
143 return messageIdentity;
144 }
145 }