[jboss-svn-commits] JBL Code SVN: r30990 - labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jan 8 16:31:14 EST 2010
Author: mark.little at jboss.com
Date: 2010-01-08 16:31:14 -0500 (Fri, 08 Jan 2010)
New Revision: 30990
Modified:
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java
Log:
https://jira.jboss.org/jira/browse/JBTM-642
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java 2010-01-08 20:00:14 UTC (rev 30989)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TwoPhaseCoordinator.java 2010-01-08 21:31:14 UTC (rev 30990)
@@ -132,38 +132,39 @@
switch (status())
{
- case ActionStatus.RUNNING:
- {
- synchronized (this)
- {
- if (_synchs == null)
- {
- // Synchronizations should be stored (or at least iterated) in their natural order
- _synchs = new TreeSet();
- }
- }
+ case ActionStatus.RUNNING:
+ case ActionStatus.PREPARING:
+ {
+ synchronized (this)
+ {
+ if (_synchs == null)
+ {
+ // Synchronizations should be stored (or at least iterated) in their natural order
+ _synchs = new TreeSet();
+ }
+ }
- // disallow addition of Synchronizations that would appear
- // earlier in sequence than any that has already been called
- // during the pre-commmit phase. This generic support is required for
- // JTA Synchronization ordering behaviour
- if(sr instanceof Comparable && _currentRecord != null) {
- Comparable c = (Comparable)sr;
- if(c.compareTo(_currentRecord) != 1) {
- return AddOutcome.AR_REJECTED;
- }
- }
- // need to guard against synchs being added while we are performing beforeCompletion processing
- synchronized (_synchs) {
- if (_synchs.add(sr))
- {
- result = AddOutcome.AR_ADDED;
- }
- }
- }
- break;
+ // disallow addition of Synchronizations that would appear
+ // earlier in sequence than any that has already been called
+ // during the pre-commmit phase. This generic support is required for
+ // JTA Synchronization ordering behaviour
+ if(sr instanceof Comparable && _currentRecord != null) {
+ Comparable c = (Comparable)sr;
+ if(c.compareTo(_currentRecord) != 1) {
+ return AddOutcome.AR_REJECTED;
+ }
+ }
+ // need to guard against synchs being added while we are performing beforeCompletion processing
+ synchronized (_synchs) {
+ if (_synchs.add(sr))
+ {
+ result = AddOutcome.AR_ADDED;
+ }
+ }
+ }
+ break;
default:
- break;
+ break;
}
return result;
@@ -222,103 +223,103 @@
synchronized (_syncLock)
{
- if (!_beforeCalled)
- {
- _beforeCalled = true;
+ if (!_beforeCalled)
+ {
+ _beforeCalled = true;
- /*
- * If we have a synchronization list then we must be top-level.
- */
+ /*
+ * If we have a synchronization list then we must be top-level.
+ */
- if (_synchs != null)
- {
- /*
- * We must always call afterCompletion() methods, so just catch (and
- * log) any exceptions/errors from beforeCompletion() methods.
- *
- * If one of the Syncs throws an error the Record wrapper returns false
- * and we will rollback. Hence we don't then bother to call beforeCompletion
- * on the remaining records (it's not done for rollabcks anyhow).
- *
- * Since Synchronizations may add register other Synchronizations, we can't simply
- * iterate the collection. Instead we work from an ordered copy, which we periodically
- * check for freshness. The addSynchronization method uses _currentRecord to disallow
- * adding records in the part of the array we have already traversed, thus all
- * Synchronization will be called and the (jta only) rules on ordering of interposed
- * Synchronization will be respected.
- */
+ if (_synchs != null)
+ {
+ /*
+ * We must always call afterCompletion() methods, so just catch (and
+ * log) any exceptions/errors from beforeCompletion() methods.
+ *
+ * If one of the Syncs throws an error the Record wrapper returns false
+ * and we will rollback. Hence we don't then bother to call beforeCompletion
+ * on the remaining records (it's not done for rollabcks anyhow).
+ *
+ * Since Synchronizations may add register other Synchronizations, we can't simply
+ * iterate the collection. Instead we work from an ordered copy, which we periodically
+ * check for freshness. The addSynchronization method uses _currentRecord to disallow
+ * adding records in the part of the array we have already traversed, thus all
+ * Synchronization will be called and the (jta only) rules on ordering of interposed
+ * Synchronization will be respected.
+ */
- int lastIndexProcessed = -1;
- SynchronizationRecord[] copiedSynchs;
- // need to guard against synchs being added while we are performing beforeCompletion processing
- synchronized (_synchs) {
- copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
- }
- while( (lastIndexProcessed < _synchs.size()-1) && !problem) {
+ int lastIndexProcessed = -1;
+ SynchronizationRecord[] copiedSynchs;
+ // need to guard against synchs being added while we are performing beforeCompletion processing
+ synchronized (_synchs) {
+ copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
+ }
+ while( (lastIndexProcessed < _synchs.size()-1) && !problem) {
- synchronized (_synchs) {
- // if new Synchronization have been registered, refresh our copy of the collection:
- if(copiedSynchs.length != _synchs.size()) {
- copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
- }
- }
+ synchronized (_synchs) {
+ // if new Synchronization have been registered, refresh our copy of the collection:
+ if(copiedSynchs.length != _synchs.size()) {
+ copiedSynchs = (SynchronizationRecord[])_synchs.toArray(new SynchronizationRecord[] {});
+ }
+ }
- lastIndexProcessed = lastIndexProcessed+1;
- _currentRecord = copiedSynchs[lastIndexProcessed];
+ lastIndexProcessed = lastIndexProcessed+1;
+ _currentRecord = copiedSynchs[lastIndexProcessed];
- try
- {
- problem = !_currentRecord.beforeCompletion();
+ try
+ {
+ problem = !_currentRecord.beforeCompletion();
- // if something goes wrong, we can't just throw the exception, we need to continue to
- // complete the transaction. However, the exception may have interesting information that
- // we want later, so we keep a reference to it as well as logging it.
+ // if something goes wrong, we can't just throw the exception, we need to continue to
+ // complete the transaction. However, the exception may have interesting information that
+ // we want later, so we keep a reference to it as well as logging it.
- }
- catch (Exception ex)
- {
- tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2", new Object[]
- { _currentRecord }, ex);
- if(_deferredThrowable == null) {
- _deferredThrowable = ex;
- }
- problem = true;
- }
- catch (Error er)
- {
- tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2", new Object[]
- { _currentRecord }, er);
- if(_deferredThrowable == null) {
- _deferredThrowable = er;
- }
- problem = true;
- }
- }
+ }
+ catch (Exception ex)
+ {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2", new Object[]
+ { _currentRecord }, ex);
+ if(_deferredThrowable == null) {
+ _deferredThrowable = ex;
+ }
+ problem = true;
+ }
+ catch (Error er)
+ {
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2", new Object[]
+ { _currentRecord }, er);
+ if(_deferredThrowable == null) {
+ _deferredThrowable = er;
+ }
+ problem = true;
+ }
+ }
- if (problem)
- {
- if (!preventCommit())
- {
- /*
- * This should not happen. If it does, continue with commit
- * to tidy-up.
- */
+ if (problem)
+ {
+ if (!preventCommit())
+ {
+ /*
+ * This should not happen. If it does, continue with commit
+ * to tidy-up.
+ */
- tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_1");
- }
- }
- }
- }
- else
- {
- /*
- * beforeCompletions already called. Assume everything is alright
- * to proceed to commit. The TM instance will flag the outcome. If
- * it's rolling back, then we'll get an exception. If it's committing
- * then we'll be blocked until the commit (assuming we're still the
- * slower thread).
- */
- }
+ tsLogger.arjLoggerI18N.warn("com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_1");
+ }
+ }
+ }
+ }
+ else
+ {
+ /*
+ * beforeCompletions already called. Assume everything is alright
+ * to proceed to commit. The TM instance will flag the outcome. If
+ * it's rolling back, then we'll get an exception. If it's committing
+ * then we'll be blocked until the commit (assuming we're still the
+ * slower thread).
+ */
+ }
}
return !problem;
More information about the jboss-svn-commits
mailing list