[jboss-cvs] JBossAS SVN: r71469 - branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 31 05:26:53 EDT 2008
Author: vicky.kak at jboss.com
Date: 2008-03-31 05:26:52 -0400 (Mon, 31 Mar 2008)
New Revision: 71469
Added:
branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsTopicPublisher.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsSessionFactoryImpl.java
Log:
[JBPAPP-662]Throw a javax.jms.IllegalStateException for jta jms activity in a failed transaction
Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsSessionFactoryImpl.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsSessionFactoryImpl.java 2008-03-31 09:24:45 UTC (rev 71468)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsSessionFactoryImpl.java 2008-03-31 09:26:52 UTC (rev 71469)
@@ -45,6 +45,7 @@
import javax.resource.spi.ManagedConnectionFactory;
import org.jboss.logging.Logger;
+import org.jboss.resource.connectionmanager.JTATransactionChecker;
/**
* Implements the JMS Connection API and produces {@link JmsSession} objects.
@@ -387,16 +388,33 @@
if (trace)
log.trace("Allocating session for " + this + " with request info=" + info);
JmsSession session = (JmsSession) cm.allocateConnection(mcf, info);
- if (trace)
- log.trace("Allocated " + this + " session=" + session);
- session.setJmsSessionFactory(this);
- if (started)
- session.start();
- sessions.add(session);
- return session;
+ try
+ {
+ if (trace)
+ log.trace("Allocated " + this + " session=" + session);
+ session.setJmsSessionFactory(this);
+ if (started)
+ session.start();
+ sessions.add(session);
+ return session;
+ }
+ catch (Throwable t)
+ {
+ try
+ {
+ session.close();
+ }
+ catch (Throwable ignored)
+ {
+ }
+ if (t instanceof Exception)
+ throw (Exception) t;
+ else
+ throw new RuntimeException("Unexpected error: ", t);
+ }
}
}
- catch (ResourceException e)
+ catch (Exception e)
{
log.error("could not create session", e);
@@ -411,5 +429,30 @@
{
if (closed)
throw new IllegalStateException("The connection is closed");
+ checkTransactionActive();
}
+
+ /**
+ * Check whether a tranasction is active
+ *
+ * @throws IllegalStateException if the transaction is not active, preparing, prepared or committing or for any error in the transaction manager
+ */
+ protected void checkTransactionActive() throws IllegalStateException
+ {
+ if (cm == null)
+ throw new IllegalStateException("No connection manager");
+ try
+ {
+ if (cm instanceof JTATransactionChecker)
+ ((JTATransactionChecker) cm).checkTransactionActive();
+ }
+ catch (Exception e)
+ {
+ IllegalStateException ex = new IllegalStateException("Transaction not active");
+ ex.initCause(e);
+ ex.setLinkedException(e);
+ throw ex;
+ }
+ }
+
}
Added: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsTopicPublisher.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsTopicPublisher.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/JmsTopicPublisher.java 2008-03-31 09:26:52 UTC (rev 71469)
@@ -0,0 +1,132 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.resource.adapter.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Topic;
+import javax.jms.TopicPublisher;
+
+import org.jboss.logging.Logger;
+
+/**
+ * JmsQueueSender.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class JmsTopicPublisher extends JmsMessageProducer implements TopicPublisher
+{
+ private static final Logger log = Logger.getLogger(JmsTopicPublisher.class);
+
+ /** Whether trace is enabled */
+ private boolean trace = log.isTraceEnabled();
+
+ /**
+ * Create a new wrapper
+ *
+ * @param producer the producer
+ * @param session the session
+ */
+ public JmsTopicPublisher(TopicPublisher producer, JmsSession session)
+ {
+ super(producer, session);
+ }
+
+ public Topic getTopic() throws JMSException
+ {
+ return ((TopicPublisher) producer).getTopic();
+ }
+
+ public void publish(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException
+ {
+ session.lock();
+ try
+ {
+ }
+ finally
+ {
+ session.unlock();
+ }
+ if (trace)
+ log.trace("send " + this + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+ checkState();
+ ((TopicPublisher) producer).publish(message, deliveryMode, priority, timeToLive);
+ if (trace)
+ log.trace("sent " + this + " result=" + message);
+ }
+
+ public void publish(Message message) throws JMSException
+ {
+ session.lock();
+ try
+ {
+ if (trace)
+ log.trace("send " + this + " message=" + message);
+ checkState();
+ ((TopicPublisher) producer).publish(message);
+ if (trace)
+ log.trace("sent " + this + " result=" + message);
+ }
+ finally
+ {
+ session.unlock();
+ }
+ }
+
+ public void publish(Topic destination, Message message, int deliveryMode, int priority, long timeToLive)
+ throws JMSException
+ {
+ session.lock();
+ try
+ {
+ if (trace)
+ log.trace("send " + this + " destination=" + destination + " message=" + message + " deliveryMode=" + deliveryMode + " priority=" + priority + " ttl=" + timeToLive);
+ checkState();
+ ((TopicPublisher) producer).publish(destination, message, deliveryMode, priority, timeToLive);
+ if (trace)
+ log.trace("sent " + this + " result=" + message);
+ }
+ finally
+ {
+ session.unlock();
+ }
+ }
+
+ public void publish(Topic destination, Message message) throws JMSException
+ {
+ session.lock();
+ try
+ {
+ if (trace)
+ log.trace("send " + this + " destination=" + destination + " message=" + message);
+ checkState();
+ ((TopicPublisher) producer).publish(destination, message);
+ if (trace)
+ log.trace("sent " + this + " result=" + message);
+ }
+ finally
+ {
+ session.unlock();
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list