1 21 package com.presumo.jms.plugin.implementation; 22 23 import com.presumo.jms.message.JmsMessage; 24 import com.presumo.jms.plugin.MessageQueue; 25 26 import java.io.IOException ; 27 import java.util.LinkedList ; 28 29 39 public class MemoryMessageQueue implements MessageQueue 40 { 41 private final LinkedList list = new LinkedList (); 47 48 public MemoryMessageQueue() 49 { 50 } 51 52 public void push(JmsMessage msg) throws IOException 53 { 54 list.add(msg); 55 } 56 57 public void push(JmsMessage [] msgs) throws IOException 58 { 59 for (int i=0; i < msgs.length; ++i) 60 list.add( msgs[i] ); 61 } 62 63 public JmsMessage getNext() throws IOException 64 { 65 return (JmsMessage) list.removeFirst(); 66 } 67 68 public JmsMessage [] getNext(int batchsize) throws IOException 69 { 70 JmsMessage [] msgs; 71 if (batchsize < list.size()) { 72 msgs = new JmsMessage[batchsize]; 73 for (int i=0; i < batchsize; ++i) 74 msgs[i] = (JmsMessage) list.removeFirst(); 75 } 76 else { 77 msgs = new JmsMessage[list.size()]; 78 list.toArray(msgs); 79 list.clear(); 80 } 81 return msgs; 82 } 83 84 public void delete(String key) throws IOException 85 { 86 } 87 88 public void delete(String [] keys) throws IOException 89 { 90 } 91 92 public int size() 93 { 94 return list.size(); 95 } 96 97 public void close() throws IOException 98 { 99 } 101 102 public boolean isPersistent() 103 { 104 return false; 105 } 106 } | Popular Tags |