Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/presumo/jms/plugin/implementation/MemoryMessageQueue.java


1   /**
2    * This file is part of Presumo.
3    *
4    * Presumo is free software; you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation; either version 2 of the License, or
7    * (at your option) any later version.
8    *
9    * Presumo is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with Presumo; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   *
19   * Copyright 2001 Dan Greff
20   */
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  /**
30   * Implementation of the MessageQueue interface in which all messages
31   * reside in memory.  Used by RemoteSession and JmsSession due to some
32   * nasty design shortcuts.  Currently also used by Router, but that
33   * will eventually be replaced by an implementation that transactionally
34   * writes persistent messages to disk and leaves non-persistent messages
35   * in memory.
36   *
37   * @author Dan Greff
38   */
39  public class MemoryMessageQueue implements MessageQueue
40  {
41    // A simpler LinkedList implementation would probably speed things
42    // up dramatically.  If somebody does decide to try putting one in
43    // be sure to do before and after performance test.  If the performance
44    // isn't dramatically better, we should probably stay with the javasoft
45    // version.
46    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      // only relevant for persistent storage queue implementations
100   }
101   
102   public boolean isPersistent()
103   {
104     return false;
105   }
106 }