KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > jms > client > JBossConsumer


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.client;
8
9 import javax.jms.Destination JavaDoc;
10 import javax.jms.JMSException JavaDoc;
11 import javax.jms.Message JavaDoc;
12 import javax.jms.MessageConsumer JavaDoc;
13 import javax.jms.MessageListener JavaDoc;
14 import javax.jms.Queue JavaDoc;
15 import javax.jms.QueueReceiver JavaDoc;
16 import javax.jms.Topic JavaDoc;
17 import javax.jms.TopicSubscriber JavaDoc;
18
19 /**
20  * A consumer
21  *
22  * @author <a HREF="mailto:adrian@jboss.org>Adrian Brock</a>
23  * @version $Revision: 1.1 $
24  */

25 public class JBossConsumer
26    implements MessageConsumer JavaDoc, QueueReceiver JavaDoc, TopicSubscriber JavaDoc
27 {
28    // Constants -----------------------------------------------------
29

30    // Attributes ----------------------------------------------------
31

32    /** The delegate */
33    private ConsumerDelegate delegate;
34
35    /** The default destination */
36    private Destination JavaDoc defaultDestination;
37
38    /** The message listener */
39    private MessageListener JavaDoc listener;
40
41    /** The message selector */
42    private String JavaDoc selector;
43
44    /** The no local flag */
45    private boolean noLocal;
46
47    // Static --------------------------------------------------------
48

49    // Constructors --------------------------------------------------
50

51    /**
52     * Create a new JBossBrowser
53     *
54     * @param delegate the delegate
55     * @param destination the destination
56     * @param selector the selector
57     * @param noLocal the no local flag
58     * @throws JMSException for any error
59     */

60    public JBossConsumer(ConsumerDelegate delegate, Destination JavaDoc destination, String JavaDoc selector, boolean noLocal)
61       throws JMSException JavaDoc
62    {
63       this.delegate = delegate;
64       this.defaultDestination = destination;
65       this.selector = selector;
66       this.noLocal = noLocal;
67    }
68
69    // Public --------------------------------------------------------
70

71    public Destination JavaDoc getDestination() throws JMSException JavaDoc
72    {
73       return defaultDestination;
74    }
75
76    // MessageConsumer implementation --------------------------------
77

78     public void close() throws JMSException JavaDoc
79     {
80       delegate.closing();
81       delegate.close();
82     }
83
84     public MessageListener JavaDoc getMessageListener() throws JMSException JavaDoc
85     {
86       return listener;
87     }
88
89     public String JavaDoc getMessageSelector() throws JMSException JavaDoc
90     {
91       return selector;
92     }
93
94     public Message JavaDoc receive() throws JMSException JavaDoc
95     {
96       return receive(0);
97     }
98
99     public Message JavaDoc receive(long timeout) throws JMSException JavaDoc
100     {
101       return delegate.receive(timeout);
102     }
103
104     public Message JavaDoc receiveNoWait() throws JMSException JavaDoc
105     {
106       return receive(-1);
107     }
108
109     public void setMessageListener(MessageListener JavaDoc listener) throws JMSException JavaDoc
110     {
111       delegate.setMessageListener(listener);
112       this.listener = listener;
113     }
114
115    // QueueReceiver implementation ----------------------------------
116

117     public Queue JavaDoc getQueue() throws JMSException JavaDoc
118     {
119       return (Queue JavaDoc) getDestination();
120     }
121
122    // TopicSubscriber implementation --------------------------------
123

124     public boolean getNoLocal() throws JMSException JavaDoc
125     {
126       return noLocal;
127     }
128
129     public Topic JavaDoc getTopic() throws JMSException JavaDoc
130     {
131       return (Topic JavaDoc) getDestination();
132     }
133
134    // Protected -----------------------------------------------------
135

136    // Package Private -----------------------------------------------
137

138    // Private -------------------------------------------------------
139

140    // Inner Classes -------------------------------------------------
141
}
142
Popular Tags