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 javax.jms.Connection;
019: import javax.jms.ConnectionConsumer;
020: import javax.jms.Destination;
021: import javax.jms.ExceptionListener;
022: import javax.jms.JMSException;
023: import javax.jms.ServerSessionPool;
024: import javax.jms.Session;
025: import javax.jms.Topic;
026: import javax.servlet.ServletContext;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: /**
032: * An implementation of {@link Connection} for DWR
033: * @author Joe Walker [joe at getahead dot ltd dot uk]
034: */
035: public class DwrConnection implements Connection {
036: /**
037: * Simple setup
038: */
039: public DwrConnection() {
040: }
041:
042: /* (non-Javadoc)
043: * @see javax.jms.Connection#createSession(boolean, int)
044: */
045: public DwrSession createSession(boolean transacted,
046: int acknowledgeMode) throws JMSException {
047: if (transacted != false) {
048: log.error("transacted == true is not currently supported");
049: }
050:
051: if (acknowledgeMode != Session.AUTO_ACKNOWLEDGE) {
052: log
053: .error("acknowledgeMode != Session.AUTO_ACKNOWLEDGE is not currently supported");
054: }
055:
056: return new DwrSession(this , transacted, acknowledgeMode);
057: }
058:
059: /* (non-Javadoc)
060: * @see javax.jms.Connection#createConnectionConsumer(javax.jms.Destination, java.lang.String, javax.jms.ServerSessionPool, int)
061: */
062: public ConnectionConsumer createConnectionConsumer(
063: Destination destination, String messageSelector,
064: ServerSessionPool sessionPool, int maxMessages)
065: throws JMSException {
066: throw Unsupported.noConnectionConsumers();
067: }
068:
069: /* (non-Javadoc)
070: * @see javax.jms.Connection#createDurableConnectionConsumer(javax.jms.Topic, java.lang.String, java.lang.String, javax.jms.ServerSessionPool, int)
071: */
072: public ConnectionConsumer createDurableConnectionConsumer(
073: Topic topic, String subscriptionName,
074: String messageSelector, ServerSessionPool sessionPool,
075: int maxMessages) throws JMSException {
076: throw Unsupported.noConnectionConsumers();
077: }
078:
079: /* (non-Javadoc)
080: * @see javax.jms.Connection#getMetaData()
081: */
082: public DwrConnectionMetaData getMetaData() throws JMSException {
083: return new DwrConnectionMetaData();
084: }
085:
086: /* (non-Javadoc)
087: * @see javax.jms.Connection#start()
088: */
089: public void start() throws JMSException {
090: if (state == State.CLOSED) {
091: throw new JMSException("Connection has been closed");
092: }
093:
094: state = State.STARTED;
095: }
096:
097: /* (non-Javadoc)
098: * @see javax.jms.Connection#stop()
099: */
100: public void stop() throws JMSException {
101: if (state == State.CLOSED) {
102: throw new JMSException("Connection has been closed");
103: }
104:
105: state = State.STOPPED;
106: }
107:
108: /* (non-Javadoc)
109: * @see javax.jms.Connection#close()
110: */
111: public void close() throws JMSException {
112: state = State.CLOSED;
113: }
114:
115: /* (non-Javadoc)
116: * @see javax.jms.Connection#setClientID(java.lang.String)
117: */
118: public void setClientID(String clientId) throws JMSException {
119: this .clientId = clientId;
120: }
121:
122: /* (non-Javadoc)
123: * @see javax.jms.Connection#getClientID()
124: */
125: public String getClientID() throws JMSException {
126: return clientId;
127: }
128:
129: /* (non-Javadoc)
130: * @see javax.jms.Connection#setExceptionListener(javax.jms.ExceptionListener)
131: */
132: public void setExceptionListener(ExceptionListener listener)
133: throws JMSException {
134: this .listener = listener;
135: }
136:
137: /* (non-Javadoc)
138: * @see javax.jms.Connection#getExceptionListener()
139: */
140: public ExceptionListener getExceptionListener() throws JMSException {
141: return listener;
142: }
143:
144: /**
145: * Children need to know if they can send messages.
146: * @return Has {@link Connection#start()} been called
147: */
148: public State getState() {
149: return state;
150: }
151:
152: /**
153: * @return the servletContext
154: */
155: public ServletContext getServletContext() {
156: return servletContext;
157: }
158:
159: /**
160: * @param servletContext the servletContext to set
161: */
162: public void setServletContext(ServletContext servletContext) {
163: this .servletContext = servletContext;
164: }
165:
166: /**
167: * Our connection to the DWR infrastructure
168: */
169: private ServletContext servletContext;
170:
171: /**
172: * What's the current state of the current connection?
173: */
174: private State state = State.STOPPED;
175:
176: /**
177: * The ID of this client
178: */
179: private String clientId;
180:
181: /**
182: * If something goes wrong we call this
183: */
184: private ExceptionListener listener;
185:
186: /**
187: * The log stream
188: */
189: private static final Log log = LogFactory
190: .getLog(DwrConnection.class);
191: }
|