KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > region > QueueBrowserSubscription


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.broker.region;
19
20 import java.io.IOException JavaDoc;
21 import javax.jms.InvalidSelectorException JavaDoc;
22 import org.apache.activemq.broker.Broker;
23 import org.apache.activemq.broker.ConnectionContext;
24 import org.apache.activemq.command.ConsumerInfo;
25 import org.apache.activemq.command.Message;
26 import org.apache.activemq.command.MessageAck;
27 import org.apache.activemq.command.MessageDispatch;
28 import org.apache.activemq.filter.MessageEvaluationContext;
29
30 public class QueueBrowserSubscription extends QueueSubscription {
31         
32     boolean browseDone;
33     
34     public QueueBrowserSubscription(Broker broker,ConnectionContext context, ConsumerInfo info) throws InvalidSelectorException JavaDoc {
35         super(broker,context, info);
36     }
37         
38     protected boolean canDispatch(MessageReference node) {
39         return !((QueueMessageReference)node).isAcked();
40     }
41     
42     public String JavaDoc toString() {
43         return
44             "QueueBrowserSubscription:" +
45             " consumer="+info.getConsumerId()+
46             ", destinations="+destinations.size()+
47             ", dispatched="+dispatched.size()+
48             ", delivered="+this.prefetchExtension+
49             ", pending="+getPendingQueueSize();
50     }
51
52     public void browseDone() throws Exception JavaDoc {
53         browseDone = true;
54         add(QueueMessageReference.NULL_MESSAGE);
55     }
56     
57     public boolean matches(MessageReference node, MessageEvaluationContext context) throws IOException JavaDoc {
58         return !browseDone && super.matches(node, context);
59     }
60
61     /**
62      * Since we are a browser we don't really remove the message from the queue.
63      */

64     protected void acknowledge(ConnectionContext context, final MessageAck ack, final MessageReference n) throws IOException JavaDoc {
65     }
66
67 }
68
Popular Tags