KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > command > MessageAck


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.command;
19
20 import org.apache.activemq.state.CommandVisitor;
21
22
23 /**
24  *
25  * @openwire:marshaller code="22"
26  * @version $Revision: 1.11 $
27  */

28 public class MessageAck extends BaseCommand {
29
30     public static final byte DATA_STRUCTURE_TYPE=CommandTypes.MESSAGE_ACK;
31
32     /**
33      * Used to let the broker know that the message has been delivered to the
34      * client. Message will still be retained until an standard ack is received.
35      * This is used get the broker to send more messages past prefetch limits when
36      * an standard ack has not been sent.
37      */

38     public static final byte DELIVERED_ACK_TYPE=0;
39     
40     /**
41      * The standard ack case where a client wants the message to be discarded.
42      */

43     public static final byte STANDARD_ACK_TYPE=2;
44
45     /**
46      * In case the client want's to explicitly let the broker know that a
47      * message was not processed and the message was considered a poison message.
48      */

49     public static final byte POSION_ACK_TYPE=1;
50     
51     protected byte ackType;
52     protected ConsumerId consumerId;
53     protected MessageId firstMessageId;
54     protected MessageId lastMessageId;
55     protected ActiveMQDestination destination;
56     protected TransactionId transactionId;
57     protected int messageCount;
58     
59     protected transient String JavaDoc consumerKey;
60     
61     public MessageAck() {
62     }
63
64     public MessageAck(MessageDispatch md, byte ackType, int messageCount) {
65         this.ackType = ackType;
66         this.consumerId = md.getConsumerId();
67         this.destination = md.getDestination();
68         this.lastMessageId = md.getMessage().getMessageId();
69         this.messageCount=messageCount;
70     }
71     
72     public void copy(MessageAck copy) {
73         super.copy(copy);
74         copy.firstMessageId = firstMessageId;
75         copy.lastMessageId = lastMessageId;
76         copy.destination = destination;
77         copy.transactionId = transactionId;
78         copy.ackType = ackType;
79         copy.consumerId = consumerId;
80     }
81
82
83     public byte getDataStructureType() {
84         return DATA_STRUCTURE_TYPE;
85     }
86     
87     public boolean isMessageAck() {
88         return true;
89     }
90
91     public boolean isPoisonAck() {
92         return ackType==POSION_ACK_TYPE;
93     }
94
95     public boolean isStandardAck() {
96         return ackType==STANDARD_ACK_TYPE;
97     }
98     
99     public boolean isDeliveredAck() {
100         return ackType==DELIVERED_ACK_TYPE;
101     }
102      
103     /**
104      * @openwire:property version=1 cache=true
105      */

106     public ActiveMQDestination getDestination() {
107         return destination;
108     }
109     public void setDestination(ActiveMQDestination destination) {
110         this.destination = destination;
111     }
112
113     /**
114      * @openwire:property version=1 cache=true
115      */

116     public TransactionId getTransactionId() {
117         return transactionId;
118     }
119     public void setTransactionId(TransactionId transactionId) {
120         this.transactionId = transactionId;
121     }
122     
123     public boolean isInTransaction() {
124         return transactionId!=null;
125     }
126
127     /**
128      * @openwire:property version=1 cache=true
129      */

130     public ConsumerId getConsumerId() {
131         return consumerId;
132     }
133     public void setConsumerId(ConsumerId consumerId) {
134         this.consumerId = consumerId;
135     }
136     
137     /**
138      * @openwire:property version=1
139      */

140     public byte getAckType() {
141         return ackType;
142     }
143     public void setAckType(byte ackType) {
144         this.ackType = ackType;
145     }
146
147     /**
148      * @openwire:property version=1
149      */

150     public MessageId getFirstMessageId() {
151         return firstMessageId;
152     }
153     public void setFirstMessageId(MessageId firstMessageId) {
154         this.firstMessageId = firstMessageId;
155     }
156
157     /**
158      * @openwire:property version=1
159      */

160     public MessageId getLastMessageId() {
161         return lastMessageId;
162     }
163     public void setLastMessageId(MessageId lastMessageId) {
164         this.lastMessageId = lastMessageId;
165     }
166
167     /**
168      * The number of messages being acknowledged in the range.
169      * @openwire:property version=1
170      */

171     public int getMessageCount() {
172         return messageCount;
173     }
174     public void setMessageCount(int messageCount) {
175         this.messageCount = messageCount;
176     }
177
178     public Response visit(CommandVisitor visitor) throws Exception JavaDoc {
179         return visitor.processMessageAck( this );
180     }
181
182     /**
183      * A helper method to allow a single message ID to be acknowledged
184      */

185     public void setMessageID(MessageId messageID) {
186         setFirstMessageId(messageID);
187         setLastMessageId(messageID);
188         setMessageCount(1);
189     }
190
191 }
192
Popular Tags