[jboss-cvs] JBossAS SVN: r91222 - branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 14 11:11:26 EDT 2009


Author: jesper.pedersen
Date: 2009-07-14 11:11:26 -0400 (Tue, 14 Jul 2009)
New Revision: 91222

Modified:
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivationSpec.java
   branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
Log:
[JBPAPP-2260] Setting maxMessages > 1 results in multiple message deliveries within one transaction

Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivationSpec.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivationSpec.java	2009-07-14 15:07:38 UTC (rev 91221)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsActivationSpec.java	2009-07-14 15:11:26 UTC (rev 91222)
@@ -127,6 +127,8 @@
    
    private int forceClearAttempts = 0;
    
+   private Boolean forceTransacted = Boolean.FALSE;
+   
    public void setForceClearOnShutdown(boolean forceClear)
    {
       this.forceClearOnShutdown = forceClear;
@@ -704,4 +706,16 @@
       this.isSameRMOverrideValue = isSameRMOverrideValue;
    }
 
+   public Boolean isForceTransacted()
+   {
+      if (forceTransacted != null)
+         return forceTransacted;
+
+      return Boolean.FALSE;
+   }
+
+   public void setForceTransacted(Boolean forceTransacted)
+   {
+      this.forceTransacted = forceTransacted;
+   }
 }
\ No newline at end of file

Modified: branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java	2009-07-14 15:07:38 UTC (rev 91221)
+++ branches/JBPAPP_4_2_0_GA_CP/connector/src/main/org/jboss/resource/adapter/jms/inflow/JmsServerSession.java	2009-07-14 15:11:26 UTC (rev 91222)
@@ -168,7 +168,8 @@
    {
       try
       {
-         endpoint.beforeDelivery(JmsActivation.ONMESSAGE);
+         if (!(txnStrategy != null && txnStrategy instanceof TraditionalXATransactionDemarcationStrategy))
+            endpoint.beforeDelivery(JmsActivation.ONMESSAGE);
 
          try
          {
@@ -180,7 +181,8 @@
          }
          finally
          {
-            endpoint.afterDelivery();
+            if (!(txnStrategy != null && txnStrategy instanceof TraditionalXATransactionDemarcationStrategy))
+               endpoint.afterDelivery();
 
             if (dlqHandler != null)
                dlqHandler.messageDelivered(message);
@@ -282,41 +284,48 @@
 
    private class DemarcationStrategyFactory
    {
-
       TransactionDemarcationStrategy getStrategy()
       {
          TransactionDemarcationStrategy current = null;
          final JmsActivationSpec spec = pool.getActivation().getActivationSpec();
          final JmsActivation activation = pool.getActivation();
+         try 
+         {
+            //If we have a transacted delivery
+            if (activation.isDeliveryTransacted())
+            {
+               //if we have an XASession
+               if (xaSession != null)
+               {
+                  if (spec.isForceTransacted())
+                  {
+                     current = new XATransactionDemarcationStrategy();
+                  }
+                  else
+                  {
+                     current = new TraditionalXATransactionDemarcationStrategy();
+                  }
+               }
+               else  //if we don't have an XASession, simulate it with a transacted session
+               {
+                  current = new SimulatedXATransactionDemarcationStrategy();
+               }
+            }
+            else
+            {
+               current = new LocalDemarcationStrategy();
+            }
+         } 
+         catch (Throwable t) 
+         {
+            log.error(this + " error creating transaction demarcation ", t);
+         }
 
-         try
-		 {
-				//If we have a transacted delivery
-        	    if (activation.isDeliveryTransacted() )
-				{
-					//if we have an XASession
-        	    	if(xaSession != null)
-					{
-						current = new XATransactionDemarcationStrategy();
-					}
-					else  //if we don't have an XASession, simulate it with a transacted session
-					{
-						current = new SimulatedXATransactionDemarcationStrategy();
-					}
-					
-				}
-        	    else
-				{
-					current = new LocalDemarcationStrategy();
-				}
-		}
-		catch (Throwable t)
-		{
-			log.error(this + " error creating transaction demarcation ", t);
-		}
-        return current;
+         if (current != null && log.isTraceEnabled())
+            log.trace("Using strategy: " + current.getClass().getName());
+
+         return current;
       }
-
    }
 
    private interface TransactionDemarcationStrategy
@@ -648,4 +657,32 @@
       }
 
    }
+
+   /**
+    * This class is used for traditional XATransaction interaction as described in JCA 1.5 12.5.6
+    */
+   private class TraditionalXATransactionDemarcationStrategy implements TransactionDemarcationStrategy
+   {
+      boolean trace = log.isTraceEnabled();
+      TransactionManager tm = pool.getActivation().getTransactionManager();;
+
+      public TraditionalXATransactionDemarcationStrategy() throws Throwable
+      {
+         final int timeout = pool.getActivation().getActivationSpec().getTransactionTimeout();
+         
+         if (timeout > 0)
+         {
+            log.trace("Setting transactionTimeout for JMSSessionPool to " + timeout);
+            tm.setTransactionTimeout(timeout);
+         }
+      }
+
+      public void error()
+      {
+      }
+
+      public void end()
+      {
+      }
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list