KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > server > list > memory > MemoryMessageList


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.jms.server.list.memory;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Comparator JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.TreeSet JavaDoc;
14
15 import org.jboss.jms.server.MessageReference;
16 import org.jboss.jms.server.list.MessageList;
17 import org.jboss.jms.server.list.StandardMessageComparator;
18
19 import EDU.oswego.cs.dl.util.concurrent.FIFOReadWriteLock;
20 import EDU.oswego.cs.dl.util.concurrent.SyncSet;
21
22 /**
23  * An in memory implementation of the message list
24  *
25  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
26  * @version $Revision: 1.1 $
27  */

28 public class MemoryMessageList
29    implements MessageList
30 {
31    // Constants -----------------------------------------------------
32

33    // Attributes ----------------------------------------------------
34

35    /** The list */
36    private SyncSet list;
37
38    // Static --------------------------------------------------------
39

40    // Constructors --------------------------------------------------
41

42    public MemoryMessageList()
43    {
44       Comparator JavaDoc comparator = new StandardMessageComparator();
45       TreeSet JavaDoc set = new TreeSet JavaDoc(comparator);
46       list = new SyncSet(set, new FIFOReadWriteLock());
47    }
48
49    // Public --------------------------------------------------------
50

51    // MessageList implementation ------------------------------------
52

53    public void add(MessageReference message)
54    {
55       list.add(message);
56    }
57    
58    public List JavaDoc browse(String JavaDoc selector)
59       throws Exception JavaDoc
60    {
61       ArrayList JavaDoc result = new ArrayList JavaDoc(list.size());
62       for (Iterator JavaDoc i = list.iterator(); i.hasNext();)
63       {
64          MessageReference reference = (MessageReference) i.next();
65          result.add(reference.getMessage());
66       }
67       return result;
68    }
69
70    // Protected ------------------------------------------------------
71

72    // Package Private ------------------------------------------------
73

74    // Private --------------------------------------------------------
75

76    // Inner Classes --------------------------------------------------
77

78 }
79
Popular Tags