1 14 package org.apache.activemq.broker.region.cursors; 15 import java.util.Iterator ; 16 import java.util.LinkedList ; 17 import org.apache.activemq.broker.region.MessageReference; 18 23 public class VMPendingMessageCursor extends AbstractPendingMessageCursor{ 24 private LinkedList <MessageReference> list = new LinkedList <MessageReference>(); 25 private Iterator <MessageReference> iter = null; 26 private MessageReference last; 27 28 31 public boolean isEmpty(){ 32 return list.isEmpty(); 33 } 34 35 39 public void reset(){ 40 iter = list.listIterator(); 41 last=null; 42 } 43 44 49 public void addMessageLast(MessageReference node){ 50 node.incrementReferenceCount(); 51 list.addLast(node); 52 } 53 54 59 public void addMessageFirst(MessageReference node){ 60 node.incrementReferenceCount(); 61 list.addFirst(node); 62 } 63 64 65 68 public boolean hasNext(){ 69 return iter.hasNext(); 70 } 71 72 75 public MessageReference next(){ 76 last = (MessageReference) iter.next(); 77 return last; 78 } 79 80 84 public void remove(){ 85 if( last!=null ) { 86 last.decrementReferenceCount(); 87 } 88 iter.remove(); 89 } 90 91 94 public int size(){ 95 return list.size(); 96 } 97 98 102 public void clear(){ 103 list.clear(); 104 } 105 106 public void remove(MessageReference node){ 107 for(Iterator <MessageReference> i=list.iterator();i.hasNext();){ 108 MessageReference ref=i.next(); 109 if(node.getMessageId().equals(ref.getMessageId())){ 110 ref.decrementReferenceCount(); 111 i.remove(); 112 break; 113 } 114 } 115 } 116 117 122 public LinkedList <MessageReference> pageInList(int maxItems) { 123 return list; 124 } 125 } 126 | Popular Tags |