KickJava   Java API By Example, From Geeks To Geeks.

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


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

19 public abstract class AbstractChannel implements Channel
20 {
21    // Constants -----------------------------------------------------
22

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

25    /** The consumer */
26    protected Consumer consumer;
27    
28    /** The channel handler */
29    protected ChannelHandler handler;
30    
31    // Static --------------------------------------------------------
32

33    // Constructors --------------------------------------------------
34

35    /**
36     * Create a new AbstractChannel.
37     *
38     * @param consumer the consumer
39     * @param handler the handler
40     */

41    public AbstractChannel(Consumer consumer, ChannelHandler handler)
42    {
43       this.consumer = consumer;
44       this.handler = handler;
45    }
46
47    // Public --------------------------------------------------------
48

49    // Channel implementation ----------------------------------------
50

51    public void send(MessageReference message)
52    {
53       handler.addMessage(message);
54    }
55
56    public MessageReference receive(long wait)
57    {
58       // There must be a message immediately available
59
if (wait == -1)
60          return handler.removeMessage(consumer);
61
62       // Wait for a message
63
handler.waitMessage(consumer, wait);
64       return null;
65    }
66    
67    public void close()
68    {
69       handler.stopWaitMessage(consumer);
70    }
71    
72    // Protected -----------------------------------------------------
73

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

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

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