1 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 ; 21 22 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 38 public StoreEntry getBatchEntry() { 39 return this.batchEntry; 40 } 41 42 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 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 |