KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > store > kahadaptor > TopicSubContainer


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

14 package org.apache.activemq.store.kahadaptor;
15
16 import org.apache.activemq.command.MessageId;
17 import org.apache.activemq.kaha.ListContainer;
18 import org.apache.activemq.kaha.StoreEntry;
19
20 import java.util.Iterator JavaDoc;
21
22 /**
23  * Holds information for the subscriber
24  *
25  * @version $Revision: 1.10 $
26  */

27 public class TopicSubContainer {
28     private ListContainer listContainer;
29     private StoreEntry batchEntry;
30
31     public TopicSubContainer(ListContainer container) {
32         this.listContainer = container;
33     }
34
35     /**
36      * @return the batchEntry
37      */

38     public StoreEntry getBatchEntry() {
39         return this.batchEntry;
40     }
41
42     /**
43      * @param batchEntry the batchEntry to set
44      */

45     public void setBatchEntry(StoreEntry batchEntry) {
46         this.batchEntry = batchEntry;
47     }
48
49     public void reset() {
50         batchEntry = null;
51     }
52
53     public boolean isEmpty() {
54         return listContainer.isEmpty();
55     }
56
57     public StoreEntry add(ConsumerMessageRef ref) {
58         return listContainer.placeLast(ref);
59     }
60
61     public ConsumerMessageRef remove(MessageId id){
62         ConsumerMessageRef result=null;
63         if(!listContainer.isEmpty()){
64             StoreEntry entry=listContainer.getFirst();
65             while(entry!=null){
66                 ConsumerMessageRef ref=(ConsumerMessageRef)listContainer.get(entry);
67                 listContainer.remove(entry);
68                 if(ref!=null&&ref.getMessageId().equals(id)){
69                     result=ref;
70                     if(listContainer!=null&&batchEntry!=null&&(listContainer.isEmpty()||batchEntry.equals(entry))){
71                         reset();
72                     }
73                     break;
74                 }
75                 entry=listContainer.getFirst();
76             }
77         }
78         return result;
79     }
80
81     public ConsumerMessageRef get(StoreEntry entry) {
82         return (ConsumerMessageRef) listContainer.get(entry);
83     }
84
85     public StoreEntry getEntry() {
86         return listContainer.getFirst();
87     }
88
89     public StoreEntry refreshEntry(StoreEntry entry) {
90         return listContainer.refresh(entry);
91     }
92
93     public StoreEntry getNextEntry(StoreEntry entry) {
94         return listContainer.getNext(entry);
95     }
96
97     public Iterator JavaDoc iterator() {
98         return listContainer.iterator();
99     }
100
101     public int size() {
102         return listContainer.size();
103     }
104
105     public void clear() {
106         reset();
107         listContainer.clear();
108     }
109 }
110
Popular Tags