KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jboss.messaging.interfaces.*;
10 import org.jboss.messaging.interfaces.Consumer;
11 import org.jboss.messaging.interfaces.MessageReference;
12
13 /**
14  * A channel handler that has only one consumer
15  *
16  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
17  * @version $Revision: 1.1 $
18  */

19 public class ExclusiveChannelHandler extends AbstractChannelHandler
20 {
21    // Constants -----------------------------------------------------
22

23    // Attributes ----------------------------------------------------
24

25    /** Set when the consumer is waiting for a message */
26    private Consumer consumer;
27
28    // Static --------------------------------------------------------
29

30    // Constructors --------------------------------------------------
31

32    /**
33     * Create a new ExclusiveChannelHandler.
34     *
35     * @param messages the message set
36     */

37    public ExclusiveChannelHandler(MessageSet messages)
38    {
39       super(messages);
40    }
41    
42    // Public --------------------------------------------------------
43

44    // AbstractChannelHandler overrides ------------------------------
45

46    protected void addConsumer(Consumer consumer, long wait)
47    {
48       this.consumer = consumer;
49    }
50
51    protected Consumer findConsumer(MessageReference reference)
52    {
53       // The messages are checked at addition to the channel
54
if (consumer != null)
55       {
56          Consumer result = consumer;
57          consumer = null;
58          return result;
59       }
60       return null;
61    }
62
63    protected void removeConsumer(Consumer consumer)
64    {
65       consumer = null;
66    }
67    
68    // Protected -----------------------------------------------------
69

70    // Package Private -----------------------------------------------
71

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

74    // Inner Classes -------------------------------------------------
75
}
76
Popular Tags