001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.jms;
017:
018: import java.io.Serializable;
019:
020: import javax.jms.BytesMessage;
021: import javax.jms.Destination;
022: import javax.jms.JMSException;
023: import javax.jms.MessageListener;
024: import javax.jms.Queue;
025: import javax.jms.QueueBrowser;
026: import javax.jms.Session;
027: import javax.jms.StreamMessage;
028: import javax.jms.TemporaryQueue;
029: import javax.jms.TemporaryTopic;
030: import javax.jms.Topic;
031: import javax.jms.TopicSubscriber;
032:
033: import org.apache.commons.logging.Log;
034: import org.apache.commons.logging.LogFactory;
035:
036: /**
037: * An implementation of {@link Session} for DWR
038: * @author Joe Walker [joe at getahead dot ltd dot uk]
039: */
040: public class DwrSession implements Session {
041: /**
042: * @see javax.jms.Connection#createSession(boolean, int)
043: * @param transacted See {@link Session#getTransacted()}
044: * @param acknowledgeMode See {@link Session#getAcknowledgeMode()}
045: * @param connection
046: */
047: public DwrSession(DwrConnection connection, boolean transacted,
048: int acknowledgeMode) {
049: if (transacted == true) {
050: throw Unsupported.noTransactions();
051: }
052:
053: if (acknowledgeMode != Session.AUTO_ACKNOWLEDGE) {
054: throw Unsupported.noManualAcknowledgment();
055: }
056:
057: this .transacted = transacted;
058: this .acknowledgeMode = acknowledgeMode;
059: this .connection = connection;
060: }
061:
062: /* (non-Javadoc)
063: * @see javax.jms.Session#createMessage()
064: */
065: public DwrMessage createMessage() throws JMSException {
066: return new DwrMessage();
067: }
068:
069: /* (non-Javadoc)
070: * @see javax.jms.Session#createMapMessage()
071: */
072: public DwrMessage createMapMessage() throws JMSException {
073: return new DwrMessage();
074: }
075:
076: /* (non-Javadoc)
077: * @see javax.jms.Session#createTextMessage()
078: */
079: public DwrMessage createTextMessage() throws JMSException {
080: return new DwrMessage();
081: }
082:
083: /* (non-Javadoc)
084: * @see javax.jms.Session#createTextMessage(java.lang.String)
085: */
086: public DwrMessage createTextMessage(String text)
087: throws JMSException {
088: return new DwrMessage(text);
089: }
090:
091: /* (non-Javadoc)
092: * @see javax.jms.Session#createStreamMessage()
093: */
094: public StreamMessage createStreamMessage() throws JMSException {
095: throw Unsupported.noBinaryMessages();
096: }
097:
098: /* (non-Javadoc)
099: * @see javax.jms.Session#createBytesMessage()
100: */
101: public BytesMessage createBytesMessage() throws JMSException {
102: throw Unsupported.noBinaryMessages();
103: }
104:
105: /* (non-Javadoc)
106: * @see javax.jms.Session#createObjectMessage()
107: */
108: public DwrMessage createObjectMessage() throws JMSException {
109: return new DwrMessage();
110: }
111:
112: /* (non-Javadoc)
113: * @see javax.jms.Session#createObjectMessage(java.io.Serializable)
114: */
115: public DwrMessage createObjectMessage(Serializable object)
116: throws JMSException {
117: return new DwrMessage(object);
118: }
119:
120: /* (non-Javadoc)
121: * @see javax.jms.Session#createBrowser(javax.jms.Queue)
122: */
123: public QueueBrowser createBrowser(Queue queue) throws JMSException {
124: throw Unsupported.noPointToPoint();
125: }
126:
127: /* (non-Javadoc)
128: * @see javax.jms.Session#createBrowser(javax.jms.Queue, java.lang.String)
129: */
130: public QueueBrowser createBrowser(Queue queue,
131: String messageSelector) throws JMSException {
132: throw Unsupported.noPointToPoint();
133: }
134:
135: /* (non-Javadoc)
136: * @see javax.jms.Session#createConsumer(javax.jms.Destination)
137: */
138: public DwrMessageConsumer createConsumer(Destination destination)
139: throws JMSException {
140: return new DwrMessageConsumer(connection, destination);
141: }
142:
143: /* (non-Javadoc)
144: * @see javax.jms.Session#createConsumer(javax.jms.Destination, java.lang.String)
145: */
146: public DwrMessageConsumer createConsumer(Destination destination,
147: String messageSelector) throws JMSException {
148: return new DwrMessageConsumer(connection, destination,
149: messageSelector);
150: }
151:
152: /* (non-Javadoc)
153: * @see javax.jms.Session#createConsumer(javax.jms.Destination, java.lang.String, boolean)
154: */
155: public DwrMessageConsumer createConsumer(Destination destination,
156: String messageSelector, boolean noLocal)
157: throws JMSException {
158: return new DwrMessageConsumer(connection, destination,
159: messageSelector, noLocal);
160: }
161:
162: /* (non-Javadoc)
163: * @see javax.jms.Session#createDurableSubscriber(javax.jms.Topic, java.lang.String)
164: */
165: public TopicSubscriber createDurableSubscriber(Topic topic,
166: String name) throws JMSException {
167: throw Unsupported.noDurableSubscriptions();
168: }
169:
170: /* (non-Javadoc)
171: * @see javax.jms.Session#createDurableSubscriber(javax.jms.Topic, java.lang.String, java.lang.String, boolean)
172: */
173: public TopicSubscriber createDurableSubscriber(Topic topic,
174: String name, String messageSelector, boolean noLocal)
175: throws JMSException {
176: throw Unsupported.noDurableSubscriptions();
177: }
178:
179: /* (non-Javadoc)
180: * @see javax.jms.Session#createProducer(javax.jms.Destination)
181: */
182: public DwrMessageProducer createProducer(Destination destination)
183: throws JMSException {
184: return new DwrMessageProducer(destination, connection);
185: }
186:
187: /* (non-Javadoc)
188: * @see javax.jms.Session#createQueue(java.lang.String)
189: */
190: public Queue createQueue(String queueName) throws JMSException {
191: throw Unsupported.noPointToPoint();
192: }
193:
194: /* (non-Javadoc)
195: * @see javax.jms.Session#createTemporaryQueue()
196: */
197: public TemporaryQueue createTemporaryQueue() throws JMSException {
198: throw Unsupported.noPointToPoint();
199: }
200:
201: /* (non-Javadoc)
202: * @see javax.jms.Session#createTopic(java.lang.String)
203: */
204: public DwrTopic createTopic(String topicName) throws JMSException {
205: return new DwrTopic(topicName);
206: }
207:
208: /* (non-Javadoc)
209: * @see javax.jms.Session#createTemporaryTopic()
210: */
211: public TemporaryTopic createTemporaryTopic() throws JMSException {
212: throw Unsupported.noTemporaryTopic();
213: }
214:
215: /* (non-Javadoc)
216: * @see javax.jms.Session#getAcknowledgeMode()
217: */
218: public int getAcknowledgeMode() throws JMSException {
219: return acknowledgeMode;
220: }
221:
222: /* (non-Javadoc)
223: * @see javax.jms.Session#setMessageListener(javax.jms.MessageListener)
224: */
225: public void setMessageListener(MessageListener messageListener)
226: throws JMSException {
227: this .messageListener = messageListener;
228: }
229:
230: /* (non-Javadoc)
231: * @see javax.jms.Session#getMessageListener()
232: */
233: public MessageListener getMessageListener() throws JMSException {
234: return messageListener;
235: }
236:
237: /* (non-Javadoc)
238: * @see javax.jms.Session#getTransacted()
239: */
240: public boolean getTransacted() throws JMSException {
241: return transacted;
242: }
243:
244: /* (non-Javadoc)
245: * @see javax.jms.Session#commit()
246: */
247: public void commit() throws JMSException {
248: if (!shownTransactionWarning) {
249: log.warn("DWR's JMS support is not transactional");
250: shownTransactionWarning = true;
251: }
252: }
253:
254: /* (non-Javadoc)
255: * @see javax.jms.Session#recover()
256: */
257: public void recover() throws JMSException {
258: throw Unsupported.noManualAcknowledgment();
259: }
260:
261: /* (non-Javadoc)
262: * @see javax.jms.Session#rollback()
263: */
264: public void rollback() throws JMSException {
265: if (!shownTransactionWarning) {
266: log.warn("DWR's JMS support is not transactional");
267: shownTransactionWarning = true;
268: }
269: }
270:
271: /* (non-Javadoc)
272: * @see javax.jms.Session#run()
273: */
274: public void run() {
275: }
276:
277: /* (non-Javadoc)
278: * @see javax.jms.Session#close()
279: */
280: public void close() throws JMSException {
281: }
282:
283: /* (non-Javadoc)
284: * @see javax.jms.Session#unsubscribe(java.lang.String)
285: */
286: public void unsubscribe(String name) throws JMSException {
287: throw Unsupported.noDurableSubscriptions();
288: }
289:
290: /**
291: * @see Unsupported#noManualAcknowledgment()
292: */
293: private int acknowledgeMode;
294:
295: /**
296: * @see Unsupported#noTransactions()
297: */
298: private boolean transacted;
299:
300: /**
301: * The current message destination
302: */
303: private MessageListener messageListener;
304:
305: /**
306: * The connection through which this session was created
307: */
308: private DwrConnection connection;
309:
310: /**
311: * We only want to show the not-transactional warning once.
312: */
313: private boolean shownTransactionWarning = false;
314:
315: /**
316: * The log stream
317: */
318: private static final Log log = LogFactory.getLog(DwrSession.class);
319: }
|