User: user57
Date: 01/08/07 17:11:41
Modified: src/main/org/jboss/jms/ra JmsSession.java
JmsSessionFactoryImpl.java
Log:
o Consolidated session open checks into getSession().
o Changed JmsSession.close() to not throw an exception if the session is
already closed (as per the API javadoc).
o Changed JmsSessionFactoryImpl to not throw an exception for close()
(as per the API javadoc); it currently does nothing which should be fixed.
Revision Changes Path
1.3 +256 -227 jboss/src/main/org/jboss/jms/ra/JmsSession.java
Index: JmsSession.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/ra/JmsSession.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JmsSession.java 2001/06/18 20:01:26 1.2
+++ JmsSession.java 2001/08/08 00:11:41 1.3
@@ -22,238 +22,267 @@
import javax.jms.*;
import javax.resource.spi.ConnectionEvent;
+
/**
- * JmsSession.java
- *
+ * Adapts the JMS QueueSession and TopicSession API to a JmsManagedConnection.
*
- * Created: Tue Apr 17 22:39:45 2001
+ * <p>Created: Tue Apr 17 22:39:45 2001
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>.
- * @version $Revision: 1.2 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>.
+ * @version $Revision: 1.3 $
*/
-
-public class JmsSession implements QueueSession, TopicSession {
- private JmsManagedConnection mc = null;
- public JmsSession(JmsManagedConnection mc) {
- this.mc = mc;
-
- }
-
- // ---- Session API
- public BytesMessage createBytesMessage() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createBytesMessage();
- }
+public class JmsSession
+ implements QueueSession, TopicSession
+{
+ /** The managed connection for this session. */
+ private JmsManagedConnection mc; // = null;
+
+ /**
+ * Construct a <tt>JmsSession</tt>.
+ *
+ * @param mc The managed connection for this session.
+ */
+ public JmsSession(final JmsManagedConnection mc) {
+ this.mc = mc;
+ }
+
+ /**
+ * Ensure that the session is opened.
+ *
+ * @return The session
+ *
+ * @throws javax.jms.IllegalStateException The session is closed
+ */
+ private Session getSession() throws JMSException {
+ // ensure that the connection is opened
+ if (mc == null)
+ throw new javax.jms.IllegalStateException("The session is closed");
+
+ return mc.getSession();
+ }
+
+ // ---- Session API
+
+ public BytesMessage createBytesMessage() throws JMSException
+ {
+ return getSession().createBytesMessage();
+ }
- public MapMessage createMapMessage() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createMapMessage();
- }
+ public MapMessage createMapMessage() throws JMSException
+ {
+ return getSession().createMapMessage();
+ }
- public Message createMessage() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createMessage();
- }
-
- public ObjectMessage createObjectMessage() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createObjectMessage();
- }
- public ObjectMessage createObjectMessage(Serializable object) throws
JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createObjectMessage(object);
- }
-
- public StreamMessage createStreamMessage() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createStreamMessage();
- }
-
- public TextMessage createTextMessage() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createTextMessage();
- }
-
- public TextMessage createTextMessage(String string) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().createTextMessage(string);
- }
- public boolean getTransacted() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return mc.getSession().getTransacted();
- }
-
- public MessageListener getMessageListener() throws JMSException
- {
-
- throw new javax.jms.IllegalStateException("Methid not allowed in J2EE");
-
- }
+ public Message createMessage() throws JMSException
+ {
+ return getSession().createMessage();
+ }
+
+ public ObjectMessage createObjectMessage() throws JMSException
+ {
+ return getSession().createObjectMessage();
+ }
+
+ public ObjectMessage createObjectMessage(Serializable object)
+ throws JMSException
+ {
+ return getSession().createObjectMessage(object);
+ }
+
+ public StreamMessage createStreamMessage() throws JMSException
+ {
+ return getSession().createStreamMessage();
+ }
+
+ public TextMessage createTextMessage() throws JMSException
+ {
+ return getSession().createTextMessage();
+ }
+
+ public TextMessage createTextMessage(String string) throws JMSException
+ {
+ return getSession().createTextMessage(string);
+ }
+
+ public boolean getTransacted() throws JMSException
+ {
+ return getSession().getTransacted();
+ }
+
+ /**
+ * Always throws an Exception.
+ *
+ * @throws javax.jms.IllegalStateException Method not allowed.
+ */
+ public MessageListener getMessageListener() throws JMSException
+ {
+ throw new javax.jms.IllegalStateException("Method not allowed");
+ }
- public void setMessageListener(MessageListener listener) throws JMSException
- {
- throw new javax.jms.IllegalStateException("Methid not allowed in J2EE");
- }
-
- public void run()
- {
- throw new Error("Methid not allowed in J2EE");
- }
-
- public void close() throws JMSException
- {
- mc.getLogger().log(Level.FINE, "Closing session");
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- // Special stuff FIXME
- mc.removeHandle(this);
- ConnectionEvent ev = new ConnectionEvent(mc,
ConnectionEvent.CONNECTION_CLOSED);
- ev.setConnectionHandle(this);
- mc.sendEvent(ev);
- mc = null;
- }
-
- // FIXME - is this really OK, probably not
- public void commit() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- mc.getSession().commit();
- }
-
- public void rollback() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- mc.getSession().rollback();
- }
-
- public synchronized void recover() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- mc.getSession().recover();
- }
-
- // --- TopicSession API
- public Topic createTopic(String topicName) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createTopic(topicName);
- }
-
- public TopicSubscriber createSubscriber(Topic topic) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createSubscriber(topic);
- }
-
- public TopicSubscriber createSubscriber(Topic topic, String messageSelector,
boolean noLocal) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createSubscriber(topic,messageSelector,
noLocal);
- }
-
- public TopicSubscriber createDurableSubscriber(Topic topic, String name) throws
JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createDurableSubscriber(topic, name);
- }
-
- public TopicSubscriber createDurableSubscriber(Topic topic, String name, String
messageSelector, boolean noLocal) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createDurableSubscriber(topic,
- name,
- messageSelector,
- noLocal);
- }
-
- public TopicPublisher createPublisher(Topic topic) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createPublisher(topic);
- }
-
- public TemporaryTopic createTemporaryTopic() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((TopicSession)mc.getSession()).createTemporaryTopic();
- }
-
- public void unsubscribe(String name) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- ((TopicSession)mc.getSession()).unsubscribe(name);
- }
-
- //--- QueueSession API
- public QueueBrowser createBrowser(Queue queue) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createBrowser(queue);
- }
-
- public QueueBrowser createBrowser(Queue queue,String messageSelector) throws
JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createBrowser(queue,messageSelector);
-
- }
-
- public Queue createQueue(String queueName) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createQueue(queueName);
- }
-
-
- public QueueReceiver createReceiver(Queue queue) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createReceiver(queue);
- }
-
- public QueueReceiver createReceiver(Queue queue, String messageSelector) throws
JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createReceiver(queue, messageSelector);
-
- }
-
- public QueueSender createSender(Queue queue) throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createSender(queue);
- }
-
- public TemporaryQueue createTemporaryQueue() throws JMSException
- {
- if (mc == null) throw new javax.jms.IllegalStateException("The session is
closed");
- return ((QueueSession)mc.getSession()).createTemporaryQueue();
- }
-
- // --- JmsManagedConnection api
- void setManagedConnection(JmsManagedConnection mc) {
- if (this.mc !=null) {
- this.mc.removeHandle(this);
- }
- this.mc = mc;
- }
-
- void destroy() {
- mc = null;
- }
-} // JmsSession
-
-
-
-
-
-
-
+ /**
+ * Always throws an Exception.
+ *
+ * @throws javax.jms.IllegalStateException Method not allowed.
+ */
+ public void setMessageListener(MessageListener listener)
+ throws JMSException
+ {
+ throw new javax.jms.IllegalStateException("Method not allowed");
+ }
+
+ /**
+ * Always throws an Error.
+ *
+ * @throws Error Method not allowed.
+ */
+ public void run() {
+ // should this really throw an Error?
+ throw new Error("Method not allowed");
+ }
+
+ /**
+ * Closes the session. Sends a ConnectionEvent.CONNECTION_CLOSED to the
+ * managed connection.
+ *
+ * @throws JMSException Failed to close session.
+ */
+ public void close() throws JMSException
+ {
+ if (mc != null) {
+ mc.getLogger().log(Level.FINE, "Closing session");
+ // Special stuff FIXME
+ mc.removeHandle(this);
+ ConnectionEvent ev =
+ new ConnectionEvent(mc, ConnectionEvent.CONNECTION_CLOSED);
+ ev.setConnectionHandle(this);
+ mc.sendEvent(ev);
+ mc = null;
+ }
+ }
+
+ // FIXME - is this really OK, probably not
+ public void commit() throws JMSException
+ {
+ getSession().commit();
+ }
+
+ public void rollback() throws JMSException
+ {
+ getSession().rollback();
+ }
+
+ public synchronized void recover() throws JMSException
+ {
+ getSession().recover();
+ }
+
+ // --- TopicSession API
+
+ public Topic createTopic(String topicName) throws JMSException
+ {
+ return ((TopicSession)getSession()).createTopic(topicName);
+ }
+
+ public TopicSubscriber createSubscriber(Topic topic) throws JMSException
+ {
+ return ((TopicSession)getSession()).createSubscriber(topic);
+ }
+
+ public TopicSubscriber createSubscriber(Topic topic,
+ String messageSelector,
+ boolean noLocal)
+ throws JMSException
+ {
+ return ((TopicSession)getSession()).
+ createSubscriber(topic,messageSelector, noLocal);
+ }
+
+ public TopicSubscriber createDurableSubscriber(Topic topic,
+ String name)
+ throws JMSException
+ {
+ return ((TopicSession)getSession()).
+ createDurableSubscriber(topic, name);
+ }
+
+ public TopicSubscriber createDurableSubscriber(Topic topic,
+ String name,
+ String messageSelector,
+ boolean noLocal)
+ throws JMSException
+ {
+ return ((TopicSession)getSession()).
+ createDurableSubscriber(topic, name, messageSelector, noLocal);
+ }
+
+ public TopicPublisher createPublisher(Topic topic) throws JMSException
+ {
+ return ((TopicSession)getSession()).createPublisher(topic);
+ }
+
+ public TemporaryTopic createTemporaryTopic() throws JMSException
+ {
+ return ((TopicSession)getSession()).createTemporaryTopic();
+ }
+
+ public void unsubscribe(String name) throws JMSException
+ {
+ ((TopicSession)getSession()).unsubscribe(name);
+ }
+
+ //--- QueueSession API
+
+ public QueueBrowser createBrowser(Queue queue) throws JMSException
+ {
+ return ((QueueSession)getSession()).createBrowser(queue);
+ }
+
+ public QueueBrowser createBrowser(Queue queue,
+ String messageSelector)
+ throws JMSException
+ {
+ return ((QueueSession)getSession()).
+ createBrowser(queue,messageSelector);
+ }
+
+ public Queue createQueue(String queueName) throws JMSException
+ {
+ return ((QueueSession)getSession()).createQueue(queueName);
+ }
+
+ public QueueReceiver createReceiver(Queue queue) throws JMSException
+ {
+ return ((QueueSession)getSession()).createReceiver(queue);
+ }
+
+ public QueueReceiver createReceiver(Queue queue, String messageSelector)
+ throws JMSException
+ {
+ return ((QueueSession)getSession()).
+ createReceiver(queue, messageSelector);
+ }
+
+ public QueueSender createSender(Queue queue) throws JMSException
+ {
+ return ((QueueSession)getSession()).createSender(queue);
+ }
+
+ public TemporaryQueue createTemporaryQueue() throws JMSException
+ {
+ return ((QueueSession)getSession()).createTemporaryQueue();
+ }
+
+ // --- JmsManagedConnection api
+
+ void setManagedConnection(final JmsManagedConnection mc) {
+ if (this.mc != null) {
+ this.mc.removeHandle(this);
+ }
+ this.mc = mc;
+ }
+
+ void destroy() {
+ mc = null;
+ }
+}
1.4 +24 -26 jboss/src/main/org/jboss/jms/ra/JmsSessionFactoryImpl.java
Index: JmsSessionFactoryImpl.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/ra/JmsSessionFactoryImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JmsSessionFactoryImpl.java 2001/07/21 02:12:04 1.3
+++ JmsSessionFactoryImpl.java 2001/08/08 00:11:41 1.4
@@ -40,12 +40,12 @@
import org.jboss.jms.ra.client.JmsSessionFactory;
/**
- * JmsSessionFactoryImpl.java
+ * Implements the JMS Connection API and produces {@link JmsSession} objects.
*
* <p>Created: Thu Mar 29 15:36:51 2001
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>.
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class JmsSessionFactoryImpl
implements JmsSessionFactory, Serializable, Referenceable
@@ -133,11 +133,11 @@
}
}
- public ConnectionConsumer
- createConnectionConsumer(Queue queue,
- String messageSelector,
- ServerSessionPool sessionPool,
- int maxMessages)
+ public ConnectionConsumer createConnectionConsumer
+ (Queue queue,
+ String messageSelector,
+ ServerSessionPool sessionPool,
+ int maxMessages)
throws JMSException
{
throw new IllegalStateException(ISE);
@@ -170,29 +170,29 @@
throw je;
}
}
-
- public ConnectionConsumer
- createConnectionConsumer(Topic topic,
- String messageSelector,
- ServerSessionPool sessionPool,
- int maxMessages)
+
+ public ConnectionConsumer createConnectionConsumer
+ (Topic topic,
+ String messageSelector,
+ ServerSessionPool sessionPool,
+ int maxMessages)
throws JMSException
{
throw new IllegalStateException(ISE);
}
- public ConnectionConsumer
- createDurableConnectionConsumer(Topic topic,
- String subscriptionName,
- String messageSelector,
- ServerSessionPool sessionPool,
- int maxMessages)
+ public ConnectionConsumer createDurableConnectionConsumer
+ (Topic topic,
+ String subscriptionName,
+ String messageSelector,
+ ServerSessionPool sessionPool,
+ int maxMessages)
throws JMSException
{
throw new IllegalStateException(ISE);
}
- //--- Al the Connection methods
+ //--- All the Connection methods
public String getClientID() throws JMSException {
throw new IllegalStateException(ISE);
@@ -224,11 +224,9 @@
throw new IllegalStateException(ISE);
}
- //
- // Why is this synchronized ?
- //
-
- public synchronized void close() throws JMSException {
- throw new IllegalStateException(ISE);
+ public void close() throws JMSException {
+ //
+ // TODO: close all sessions, for now just do nothing.
+ //
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development