KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > messaging > channel > plugins > handler > SharedChannelHandler


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.messaging.channel.plugins.handler;
8
9 import java.util.ArrayList JavaDoc;
10
11 import org.jboss.messaging.interfaces.*;
12 import org.jboss.messaging.interfaces.Consumer;
13 import org.jboss.messaging.interfaces.MessageReference;
14
15 /**
16  * A channel handler that has multiple consumers
17  *
18  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
19  * @version $Revision: 1.1 $
20  */

21 public class SharedChannelHandler extends AbstractChannelHandler
22 {
23    // Constants -----------------------------------------------------
24

25    // Attributes ----------------------------------------------------
26

27    /** The waiting consumers */
28    private ArrayList JavaDoc consumers = new ArrayList JavaDoc();
29
30    // Static --------------------------------------------------------
31

32    // Constructors --------------------------------------------------
33

34    /**
35     * Create a new SharedChannelHandler.
36     *
37     * @param messages the message set
38     */

39    public SharedChannelHandler(MessageSet messages)
40    {
41       super(messages);
42    }
43    
44    // Public --------------------------------------------------------
45

46    // AbstractChannelHandler overrides ------------------------------
47

48    protected void addConsumer(Consumer consumer, long wait)
49    {
50       consumers.add(consumer);
51    }
52
53    protected Consumer findConsumer(MessageReference reference)
54    {
55       for (int i = 0; i < consumers.size(); ++i)
56       {
57          Consumer consumer = (Consumer) consumers.get(i);
58          if (consumer.accepts(reference, true))
59          {
60             consumers.remove(i);
61             return consumer;
62          }
63       }
64       return null;
65    }
66
67    protected void removeConsumer(Consumer consumer)
68    {
69       consumers.remove(consumer);
70    }
71    
72    // Protected -----------------------------------------------------
73

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

76    // Private -------------------------------------------------------
77

78    // Inner Classes -------------------------------------------------
79
}
80
Popular Tags