1 /*
2 * @(#)MessageConsumerImpl.java
3 *
4 * JFoxMQ the open source JMS MOM.
5 *
6 * Corpyright 2002-2003 Huihoo Power, Inc. All Rights Reserved. This software
7 * is licensed under LGPL license.
8 *
9 * For more information, please visit: http://www.huihoo.org
10 */
11
12 package org.huihoo.jfox.ms.jms.base;
13
14 import javax.jms.JMSException;
15 import javax.jms.Message;
16 import javax.jms.MessageConsumer;
17 import javax.jms.MessageListener;
18
19 /***
20 * <p>
21 * This class implements the JMS message producer. A client uses a
22 * MessageConsumer object to receive messages from a destination. A
23 * MessageConsumer object is created by passing a Destination object to a
24 * message-consumer creation method supplied by a session.
25 * </p>
26 *
27 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter.Cheng</a>
28 * @version Revision: 1.1 Date: 2003-05-20 21:36:14
29 */
30
31 public abstract class MessageConsumerImpl implements MessageConsumer {
32
33 // The client specified message selector.
34 private String messageSelector;
35
36 // The session under which this consumer is serviced.
37 private SessionImpl session;
38
39 private MessageListener messageListener;
40
41 private boolean closed = false;
42
43 public MessageConsumerImpl(SessionImpl session, String messageSelector) {
44 this.session = session;
45 this.messageSelector = messageSelector;
46 }
47
48 /***
49 * Gets the message consumer's <CODE>MessageListener</CODE>.
50 *
51 * @return the listener for the message consumer, or null if no listener is
52 * set
53 * @return @throws
54 * JMSException
55 */
56 public MessageListener getMessageListener() throws JMSException {
57 if (isClosed()) {
58 throw new javax.jms.IllegalStateException(
59 "The message consumer is closed.");
60 }
61 return this.messageListener;
62 }
63
64 /***
65 * ets the message consumer's MessageListener.
66 *
67 * <P>
68 * Setting the message listener to null is the equivalent of unsetting the
69 * message listener for the message consumer.
70 *
71 * <P>
72 * The effect of calling MessageConsumer.setMessageListener while messages
73 * are being consumed by an existing listener or the consumer is being used
74 * to consume messages synchronously is undefined.
75 *
76 * @param listener
77 * the listener to which the messages are to be delivered
78 * @throws JMSException
79 */
80 public void setMessageListener(MessageListener listener)
81 throws JMSException {
82 if (isClosed()) {
83 throw new javax.jms.IllegalStateException(
84 "The message consumer is closed.");
85 }
86 this.messageListener = listener;
87 }
88
89 /***
90 * Gets this message consumer's message selector expression.
91 *
92 * @return this message consumer's message selector, or null if no message
93 * selector exists for the message consumer (that is, if the
94 * message selector was not set or was set to null or the empty
95 * string)
96 * @return @throws
97 * JMSException
98 */
99 public String getMessageSelector() throws JMSException {
100 if (isClosed()) {
101 throw new javax.jms.IllegalStateException(
102 "The message consumer is closed.");
103 }
104 return this.messageSelector;
105 }
106
107 /***
108 * Receives the next message produced for this message consumer. If no
109 * message is available, this call will block until a message can be
110 * received.
111 *
112 * <p>
113 * This call blocks indefinitely until a message is produced or until this
114 * message consumer is closed.
115 *
116 * <p>
117 * If this receive is done within a transaction, the consumer retains the
118 * message until the transaction commits.
119 *
120 * @return the next message produced for this message consumer, or null if
121 * this message consumer is concurrently closed
122 * @throws JMSException
123 */
124 public Message receive() throws JMSException {
125 if (isClosed()) {
126 throw new javax.jms.IllegalStateException(
127 "The message consumer is closed.");
128 }
129 return receive(0);
130
131 }
132
133 /***
134 * Receives the next message that arrives within the specified timeout
135 * interval.
136 *
137 * <P>
138 * This call blocks until a message arrives, the timeout expires, or this
139 * message consumer is closed. A <CODE>timeout</CODE> of zero never
140 * expires, and the call blocks indefinitely.
141 *
142 * @param timeout
143 * the timeout value (in milliseconds)
144 * @return the next message produced for this message consumer, or null if
145 * the timeout expires or this message consumer is concurrently
146 * closed
147 * @throws JMSException
148 */
149 public Message receive(long timeout) throws JMSException {
150 if (isClosed()) {
151 throw new javax.jms.IllegalStateException(
152 "The message consumer is closed.");
153 }
154 return null;
155 }
156
157 /***
158 * Receives the next message if one is immediately available.Do not wait
159 * for a message to be recevied.
160 *
161 * @return the next message produced for this message consumer, or null if
162 * one is not available
163 * @throws JMSException
164 */
165 public Message receiveNoWait() throws JMSException {
166 if (isClosed()) {
167 throw new javax.jms.IllegalStateException(
168 "The message consumer is closed.");
169 }
170 return null;
171 }
172
173 /***
174 * Closes the message consumer.
175 *
176 * <p>
177 * Since a provider may allocate some resources on behalf of a
178 * MessageConsumer outside the Java virtual machine, clients should close
179 * them when they are not needed. Relying on garbage collection to
180 * eventually reclaim these resources may not be timely enough.
181 *
182 * <p>
183 * This call blocks until a receive or message listener in progress has
184 * completed. A blocked message consumer receive call
185 *
186 * @throws JMSException
187 */
188 public void close() throws JMSException {
189 }
190
191 /***
192 * Indicates the status of this message consumer.
193 *
194 * @return true if the message consumer is closed
195 */
196 public boolean isClosed() {
197 return closed;
198 }
199 }
This page was automatically generated by Maven