[jboss-cvs] JBossAS SVN: r83503 - trunk/connector/src/main/org/jboss/resource/adapter/jms/inflow.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 27 10:22:12 EST 2009
Author: jhowell at redhat.com
Date: 2009-01-27 10:22:12 -0500 (Tue, 27 Jan 2009)
New Revision: 83503
Modified:
trunk/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
Log:
[JBAS-6343] - change local demarcation strategy so that it supports non-xa connection factories using transacted sessions.
Modified: trunk/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
===================================================================
--- trunk/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java 2009-01-27 14:52:31 UTC (rev 83502)
+++ trunk/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java 2009-01-27 15:22:12 UTC (rev 83503)
@@ -281,30 +281,27 @@
TransactionDemarcationStrategy getStrategy()
{
TransactionDemarcationStrategy current = null;
- final JmsActivationSpec spec = pool.getActivation()
- .getActivationSpec();
- final JmsActivation activation = pool.getActivation();
+ final JmsActivationSpec spec = pool.getActivation()
+ .getActivationSpec();
+ final JmsActivation activation = pool.getActivation();
+ try
+ {
+ if (activation.isDeliveryTransacted() && xaSession != null)
+ {
+ current = new XATransactionDemarcationStrategy();
+ }
+ else
+ {
+ current = new LocalDemarcationStrategy();
+ }
+ }
+ catch (Throwable t)
+ {
+ log.error(this + " error creating transaction demarcation ", t);
+ }
+ return current;
+ }
- if (activation.isDeliveryTransacted() && xaSession != null)
- {
- try
- {
- current = new XATransactionDemarcationStrategy();
- } catch (Throwable t)
- {
- log.error(this + " error creating transaction demarcation ", t);
- }
-
- } else
- {
-
- return new LocalDemarcationStrategy();
-
- }
-
- return current;
- }
-
}
private interface TransactionDemarcationStrategy
@@ -315,33 +312,40 @@
}
- private class LocalDemarcationStrategy implements
- TransactionDemarcationStrategy
+ /**
+ * JBAS-6343 - This class is exactly like the XADemarcationStrategy, but it uses a transacted session under the covers.
+ * Unfortuneately we have to start a transaction the for local, because we need to be able to get a handle to any failed
+ * transactions.
+ * @author jhowell
+ *
+ */
+ private class LocalDemarcationStrategy implements TransactionDemarcationStrategy
{
- public void end()
+
+ boolean trace = log.isTraceEnabled();
+
+ Transaction trans = null;
+
+ TransactionManager tm = pool.getActivation().getTransactionManager();;
+
+ public LocalDemarcationStrategy() throws Throwable
{
- final JmsActivationSpec spec = pool.getActivation()
- .getActivationSpec();
- if (spec.isSessionTransacted())
+ final int timeout = pool.getActivation().getActivationSpec().getTransactionTimeout();
+
+ if (timeout > 0)
{
- if (session != null)
- {
- try
- {
- session.commit();
- } catch (JMSException e)
- {
- log.error("Failed to commit session transaction", e);
- }
- }
+ log.trace("Setting transactionTimeout for JMSSessionPool to " + timeout);
+ tm.setTransactionTimeout(timeout);
}
+ //we need to begin a tx so that we can get a handle to the tx in end. In end we will roll back the session.
+ tm.begin();
+ trans=tm.getTransaction();
}
public void error()
{
- final JmsActivationSpec spec = pool.getActivation()
- .getActivationSpec();
+ final JmsActivationSpec spec = pool.getActivation().getActivationSpec();
if (spec.isSessionTransacted())
{
@@ -349,23 +353,24 @@
try
{
- /*
+
+ /*
* Looks strange, but this basically means
*
- * If the underlying connection was non-XA and the transaction
- * attribute is REQUIRED we rollback. Also, if the underlying
- * connection was non-XA and the transaction attribute is
- * NOT_SUPPORT and the non standard redelivery behavior is
- * enabled we rollback to force redelivery.
+ * JBAS-6343 - If the underlying connection was non-XA and the transaction attribute is REQUIRED
+ * we rollback. Also, if the underlying connection was non-XA and the transaction
+ * attribute is NOT_SUPPORT and the non standard redelivery behavior is enabled
+ * we rollback to force redelivery.
*
*/
- if (pool.getActivation().isDeliveryTransacted()
- || spec.getRedeliverUnspecified())
+ if (pool.getActivation().isDeliveryTransacted() || spec.getRedeliverUnspecified())
{
- session.rollback();
+ log.debug(JmsServerSession.this +"Rolling transacted session back due to an error");
+ session.rollback();
}
- } catch (JMSException e)
+ }
+ catch (JMSException e)
{
log.error("Failed to rollback session transaction", e);
}
@@ -373,6 +378,62 @@
}
}
+ public void end()
+ {
+ try
+ {
+
+ // Use the TM to commit the Tx (assert the correct association)
+ Transaction currentTx = tm.getTransaction();
+ if (trans.equals(currentTx) == false)
+ throw new IllegalStateException("Wrong tx association: expected " + trans + " was " + currentTx);
+
+ // Marked rollback
+ if (trans.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+ {
+ log.trace(JmsServerSession.this + " rolling Transacted session back due to Transaction Rollback");
+ //call to error, if we are rolled back
+ error();
+ }
+
+ else if (trans.getStatus() == Status.STATUS_ACTIVE)
+ {
+ // Commit tx
+ // This will happen if
+ // a) everything goes well
+ // b) app. exception was thrown
+ if (trace)
+ log.trace(JmsServerSession.this + " commiting the JMS transaction tx=" + trans);
+ tm.commit();
+
+ // NO XASession? then manually commit. This is not so good but
+ // it's the best we can do if we have no XASession.
+ if (xaSession == null && pool.getActivation().isDeliveryTransacted())
+ {
+ log.trace(JmsServerSession.this + " commiting Transacted session");
+ session.commit();
+ }
+
+ }
+ else
+ {
+ tm.suspend();
+
+ if (xaSession == null && pool.getActivation().isDeliveryTransacted())
+ {
+ session.rollback();
+ }
+
+ }
+
+ }
+ catch (Throwable t)
+ {
+ log.error(JmsServerSession.this + " failed to commit/rollback", t);
+ }
+
+ }
+
}
private class XATransactionDemarcationStrategy implements
@@ -485,7 +546,7 @@
session.rollback();
}
}
-
+
else if (trans.getStatus() == Status.STATUS_ACTIVE)
{
// Commit tx
More information about the jboss-cvs-commits
mailing list