You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2011/09/12 15:24:58 UTC

svn commit: r1169737 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: TransactionContext.java XASessionImpl.java

Author: jukka
Date: Mon Sep 12 13:24:58 2011
New Revision: 1169737

URL: http://svn.apache.org/viewvc?rev=1169737&view=rev
Log:
JCR-3067: Remove timeout handling from TransactionContext

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=1169737&r1=1169736&r2=1169737&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java Mon Sep 12 13:24:58 2011
@@ -16,16 +16,15 @@
  */
 package org.apache.jackrabbit.core;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.jackrabbit.util.Timer;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.Xid;
 
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Represents the transaction on behalf of the component that wants to
@@ -35,7 +34,7 @@ import java.util.Map;
  * of the resources' {@link InternalXAResource#prepare} method, are eventually
  * unlocked.
  */
-public class TransactionContext extends Timer.Task {
+public class TransactionContext {
 
     /**
      * Logger instance.
@@ -55,26 +54,11 @@ public class TransactionContext extends 
     private static final ThreadLocal<Xid> CURRENT_XID = new ThreadLocal<Xid>();
 
     /**
-     * Timer for all transaction contexts.
-     */
-    private final Timer timer;
-
-    /**
      * Transactional resources.
      */
     private final InternalXAResource[] resources;
 
     /**
-     * Timeout, in seconds.
-     */
-    private final int timeout;
-
-    /**
-     * Indicates if this {@link TransactionContext} has timed out internally
-     */
-    private boolean timedOut = false;
-
-    /**
     * The Xid
     */
    private final Xid xid;
@@ -96,17 +80,13 @@ public class TransactionContext extends 
 
     /**
      * Create a new instance of this class.
+     *
      * @param xid associated xid
      * @param resources transactional resources
-     * @param timeout timeout, in seconds
      */
-    public TransactionContext(
-            Xid xid, InternalXAResource[] resources,
-            int timeout, Timer timer) {
+    public TransactionContext(Xid xid, InternalXAResource[] resources) {
         this.xid = xid;
         this.resources = resources;
-        this.timeout = timeout;
-        this.timer = timer;
     }
 
     /**
@@ -149,11 +129,10 @@ public class TransactionContext extends 
      * all resources. If some resource reports an error on prepare,
      * automatically rollback changes on all other resources. Throw exception
      * at the end if errors were found.
-     * @param onePhaseOptimized if true this prepare comes from a onePhase optimized Transaction.
-     * 			Internal Timeout-Task will be started.
+     *
      * @throws XAException if an error occurs
      */
-    public synchronized void prepare(boolean onePhaseOptimized) throws XAException {
+    public synchronized void prepare() throws XAException {
         bindCurrentXid();
         status = STATUS_PREPARING;
         beforeOperation();
@@ -182,11 +161,6 @@ public class TransactionContext extends 
             e.initCause(txe);
             throw e;
         }
-
-        if (onePhaseOptimized) {
-            // start rollback task in case the commit is never issued
-            timer.schedule(this, timeout * 1000, Integer.MAX_VALUE);
-        }
     }
 
     /**
@@ -194,17 +168,14 @@ public class TransactionContext extends 
      * all resources. If some resource reports an error on commit,
      * automatically rollback changes on all other resources. Throw
      * exception at the end if some commit failed.
-     * @param true if the commit comes from a onePhase optimized Transaction.
+     *
      * @throws XAException if an error occurs
      */
-    public synchronized void commit(boolean onePhase) throws XAException {
+    public synchronized void commit() throws XAException {
         if (status == STATUS_ROLLED_BACK) {
-        	if (onePhase && timedOut) {
-        		throw new XAException(XAException.XA_RBTIMEOUT);
-        	} else {
-        		throw new XAException(XAException.XA_HEURRB);
-        	}
+            throw new XAException(XAException.XA_HEURRB);
         }
+
         boolean heuristicCommit = false;
         bindCurrentXid();
         status = STATUS_COMMITTING;
@@ -231,21 +202,17 @@ public class TransactionContext extends 
         afterOperation();
         status = STATUS_COMMITTED;
 
-        if (onePhase) {
-        	// cancel the rollback task only in onePhase Transactions
-        	cancel();
-        }
         cleanCurrentXid();
 
         if (txe != null) {
-        	XAException e = null;
-        	if (heuristicCommit) {
-        		e = new XAException(XAException.XA_HEURMIX);
-        	} else {
-        		e = new XAException(XAException.XA_HEURRB);
-        	}
-    		e.initCause(txe);
-    		throw e;
+            XAException e = null;
+            if (heuristicCommit) {
+                e = new XAException(XAException.XA_HEURMIX);
+            } else {
+                e = new XAException(XAException.XA_HEURRB);
+            }
+            e.initCause(txe);
+            throw e;
         }
     }
 
@@ -275,8 +242,6 @@ public class TransactionContext extends 
         afterOperation();
         status = STATUS_ROLLED_BACK;
 
-        // cancel the rollback task
-        cancel();
         cleanCurrentXid();
 
         if (errors != 0) {
@@ -285,26 +250,6 @@ public class TransactionContext extends 
     }
 
     /**
-     * Rolls back the transaction if still prepared and marks the transaction
-     * rolled back.
-     */
-    public void run() {
-        synchronized (this) {
-            if (status == STATUS_PREPARED) {
-                try {
-                    rollback();
-                } catch (XAException e) {
-                    /* ignore */
-                }
-                timedOut = true;
-                log.warn("Transaction rolled back because timeout expired.");
-            }
-            // cancel the rollback task
-            cancel();
-        }
-    }
-
-    /**
      * Invoke all of the registered resources' {@link InternalXAResource#beforeOperation}
      * methods.
      */

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java?rev=1169737&r1=1169736&r2=1169737&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java Mon Sep 12 13:24:58 2011
@@ -251,9 +251,7 @@ public class XASessionImpl extends Sessi
      * @return transaction context
      */
     private TransactionContext createTransaction(Xid xid) {
-        TransactionContext tx = new TransactionContext(
-                xid, txResources,
-                getTransactionTimeout(), repositoryContext.getTimer());
+        TransactionContext tx = new TransactionContext(xid, txResources);
         txGlobal.put(xid, tx);
         return tx;
     }
@@ -309,7 +307,7 @@ public class XASessionImpl extends Sessi
         if (tx == null) {
             throw new XAException(XAException.XAER_NOTA);
         }
-        tx.prepare(false);
+        tx.prepare();
         return XA_OK;
     }
 
@@ -322,9 +320,9 @@ public class XASessionImpl extends Sessi
             throw new XAException(XAException.XAER_NOTA);
         }
         if (onePhase) {
-            tx.prepare(onePhase);
+            tx.prepare();
         }
-        tx.commit(onePhase);
+        tx.commit();
 
         txGlobal.remove(xid);
     }