aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1694014 - in /aries/trunk/transaction/transaction-blueprint/src: main/java/org/apache/aries/transaction/ test/java/org/apache/aries/transaction/
Date Tue, 04 Aug 2015 08:51:47 GMT
Author: cschneider
Date: Tue Aug  4 08:51:47 2015
New Revision: 1694014

URL: http://svn.apache.org/r1694014
Log:
[ARIES-1362] Hold a reference to coordination to avoid it to be considered ORPHANED

Modified:
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
    aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
    aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java?rev=1694014&r1=1694013&r2=1694014&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TransactionToken.java
Tue Aug  4 08:51:47 2015
@@ -20,12 +20,15 @@ package org.apache.aries.transaction;
 
 import javax.transaction.Transaction;
 
+import org.osgi.service.coordinator.Coordination;
+
 public class TransactionToken
 {
    private Transaction activeTransaction;
    private Transaction suspendedTransaction;
    private TransactionAttribute transactionAttribute;
    private boolean isCompletionAllowed;
+   private Coordination coordination;
    
    public TransactionToken(Transaction activeTransaction, Transaction suspendedTransaction,
            TransactionAttribute transactionAttribute)
@@ -57,4 +60,12 @@ public class TransactionToken
    public boolean isCompletionAllowed() {
        return isCompletionAllowed;
    }
+   
+   public Coordination getCoordination() {
+    return coordination;
+   }
+   
+   public void setCoordination(Coordination coordination) {
+    this.coordination = coordination;
+   }
 }
\ No newline at end of file

Modified: aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java?rev=1694014&r1=1694013&r2=1694014&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxInterceptorImpl.java
Tue Aug  4 08:51:47 2015
@@ -27,6 +27,7 @@ import org.apache.aries.blueprint.Interc
 import org.apache.aries.transaction.annotations.TransactionPropagationType;
 import org.apache.aries.transaction.exception.TransactionRollbackException;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.coordinator.Coordination;
 import org.osgi.service.coordinator.Coordinator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,7 +55,9 @@ public class TxInterceptorImpl implement
 
         LOGGER.debug("PreCall for bean {}, method {} with tx strategy {}.", getCmId(cm),
m.getName(), txAttribute);
         TransactionToken token = txAttribute.begin(tm);
-        coordinator.begin("txInterceptor." + m.getDeclaringClass().getName() + "." + m.getName()
, 0);
+        String coordName = "txInterceptor." + m.getDeclaringClass().getName() + "." + m.getName();
+        Coordination coord = coordinator.begin(coordName , 0);
+        token.setCoordination(coord);
         return token;
     }
 
@@ -63,8 +66,8 @@ public class TxInterceptorImpl implement
         if (!(preCallToken instanceof TransactionToken)) {
             return;
         }
-        endCoordination();
         final TransactionToken token = (TransactionToken)preCallToken;
+        token.getCoordination().end();
         try {
             Transaction tran = token.getActiveTransaction();
             if (tran != null && isRollBackException(ex)) {
@@ -88,9 +91,9 @@ public class TxInterceptorImpl implement
         if (preCallToken == null) {
             return;
         }
-        endCoordination();
         if (preCallToken instanceof TransactionToken) {
             final TransactionToken token = (TransactionToken)preCallToken;
+            token.getCoordination().end();
             try {
                 token.getTransactionAttribute().finish(tm, token);
             } catch (Exception e) {
@@ -103,14 +106,6 @@ public class TxInterceptorImpl implement
         }
     }
 
-    private void endCoordination() {
-        try {
-            coordinator.pop().end();
-        } catch (Exception e) {
-            LOGGER.warn("Error ending coordination ", e);
-        }
-    }
-
     private boolean isRollBackException(Throwable ex) {
         return ex instanceof RuntimeException || ex instanceof Error;
     }

Modified: aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java?rev=1694014&r1=1694013&r2=1694014&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
(original)
+++ aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/InterceptorTest.java
Tue Aug  4 08:51:47 2015
@@ -26,6 +26,7 @@ import javax.transaction.TransactionMana
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
 import org.junit.Test;
+import org.osgi.service.coordinator.Coordination;
 
 public class InterceptorTest {
 
@@ -47,9 +48,14 @@ public class InterceptorTest {
             tran.setRollbackOnly();
             EasyMock.expectLastCall();
         }
+        Coordination coordination = c.createMock(Coordination.class);
+        coordination.end();
+        EasyMock.expectLastCall();
         
         c.replay();
         TransactionToken tt = new TransactionToken(tran, null, TransactionAttribute.REQUIRED);
+        
+        tt.setCoordination(coordination );
         sut.postCallWithException(null, this.getClass().getMethods()[0], th, tt);
         c.verify();
     }



Mime
View raw message