use of com.arjuna.ats.internal.jts.resources.SynchronizationRecord in project narayana by jbosstm.
the class ArjunaTransactionImple method getSynchronizations.
public java.util.Map<Uid, String> getSynchronizations() {
if (_synchs != null) {
java.util.Map<Uid, String> synchMap = new java.util.HashMap<Uid, String>();
SynchronizationRecord[] synchs = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
for (SynchronizationRecord synch : synchs) {
Synchronization c = synch.contents();
String cn;
if (c._is_a(ManagedSynchronizationHelper.id())) {
ManagedSynchronization mc = ManagedSynchronizationHelper.narrow(c);
try {
// implementationType() ;
cn = mc.instanceName();
} catch (Throwable t) {
cn = synch.getClass().getCanonicalName();
}
} else {
cn = synch.getClass().getCanonicalName();
}
synchMap.put(synch.get_uid(), cn);
}
return synchMap;
}
return Collections.EMPTY_MAP;
}
use of com.arjuna.ats.internal.jts.resources.SynchronizationRecord in project narayana by jbosstm.
the class ArjunaTransactionImple method doAfterCompletion.
protected void doAfterCompletion(org.omg.CosTransactions.Status myStatus) throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::doAfterCompletion for " + get_uid());
}
if (myStatus == Status.StatusActive) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_txrun("ArjunaTransactionImple.doAfterCompletion");
return;
}
boolean problem = false;
SystemException exp = null;
if (_synchs != null) {
ControlWrapper cw = null;
boolean doSuspend = false;
try {
// cw = OTSImpleManager.systemCurrent().getControlWrapper();
cw = OTSImpleManager.current().getControlWrapper();
if ((cw == null) || (!controlHandle.equals(cw.getImple()))) {
// OTSImpleManager.systemCurrent().resumeImple(controlHandle);
OTSImpleManager.current().resumeImple(controlHandle);
doSuspend = true;
}
} catch (Exception ex) {
/*
* It should still be OK to make the call without a context
* because a Synchronization can only be associated with a
* single transaction.
*/
problem = true;
}
/*
* Regardless of failures, we must tell all synchronizations what
* happened.
*/
// afterCompletions should run in reverse order compared to beforeCompletions
Stack stack = new Stack();
Iterator iterator = _synchs.iterator();
while (iterator.hasNext()) {
stack.push(iterator.next());
}
iterator = stack.iterator();
/*
* Regardless of failures, we must tell all synchronizations what
* happened.
*/
while (!stack.isEmpty()) {
SynchronizationRecord value = (SynchronizationRecord) stack.pop();
Synchronization c = value.contents();
try {
c.after_completion(myStatus);
} catch (SystemException e) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple.doAfterCompletion - caught exception " + e);
}
problem = true;
if (exp == null)
exp = e;
}
}
if (doSuspend) {
try {
if (cw != null)
OTSImpleManager.current().resumeWrapper(cw);
else
OTSImpleManager.current().suspend();
} catch (Exception ex) {
}
}
_synchs = null;
}
boolean superProblem = !super.afterCompletion(myStatus == Status.StatusCommitted ? ActionStatus.COMMITTED : ActionStatus.ABORTED);
if (problem || superProblem) {
if (exp != null)
throw exp;
else
throw new UNKNOWN(ExceptionCodes.SYNCHRONIZATION_EXCEPTION, CompletionStatus.COMPLETED_NO);
}
}
use of com.arjuna.ats.internal.jts.resources.SynchronizationRecord in project narayana by jbosstm.
the class ArjunaTransactionImple method doBeforeCompletion.
protected void doBeforeCompletion() throws SystemException {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::doBeforeCompletion for " + get_uid());
}
boolean problem = false;
SystemException exp = null;
/*
* If we have a synchronization list then we must be top-level.
*/
if (_synchs != null) {
boolean doSuspend = false;
ControlWrapper cw = null;
try {
try {
// cw = OTSImpleManager.systemCurrent().getControlWrapper();
cw = OTSImpleManager.current().getControlWrapper();
if ((cw == null) || (!controlHandle.equals(cw.getImple()))) {
// OTSImpleManager.systemCurrent().resumeImple(controlHandle);
OTSImpleManager.current().resumeImple(controlHandle);
doSuspend = true;
}
} catch (Exception ex) {
/*
* It should be OK to continue with the invocations even if
* we couldn't resume, because a Synchronization is only
* supposed to be associated with a single transaction. So,
* it should be able to infer the transaction.
*/
}
/*
* 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 = (SynchronizationRecord[]) _synchs.toArray(new SynchronizationRecord[] {});
while ((lastIndexProcessed < _synchs.size() - 1) && !problem) {
// 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];
Synchronization c = _currentRecord.contents();
c.before_completion();
}
} catch (SystemException e) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_generror("ArjunaTransactionImple.doBeforeCompletion", e);
if (!problem) {
exp = e;
problem = true;
try {
rollback_only();
} catch (Inactive ex) {
/*
* This should not happen. If it does, continue with
* commit to tidy-up.
*/
jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.doBeforeCompletion", get_uid(), ex);
}
}
} finally {
if (doSuspend) {
try {
if (cw != null)
OTSImpleManager.current().resumeWrapper(cw);
else
OTSImpleManager.current().suspend();
} catch (Exception ex) {
}
// OTSImpleManager.systemCurrent().suspend();
}
}
}
if (!problem)
problem = !super.beforeCompletion();
if (problem) {
if (exp != null)
throw exp;
else
throw new UNKNOWN(ExceptionCodes.SYNCHRONIZATION_EXCEPTION, CompletionStatus.COMPLETED_NO);
}
}
use of com.arjuna.ats.internal.jts.resources.SynchronizationRecord in project narayana by jbosstm.
the class SynchronizationRecordUnitTest method testCompare.
@Test
public void testCompare() throws Exception {
demosync theSync = new demosync();
SynchronizationRecord sync1 = new SynchronizationRecord(theSync.getReference(), false);
SynchronizationRecord sync2 = new SynchronizationRecord(theSync.getReference(), true);
assertEquals(sync1.compareTo(sync2), -1);
assertEquals(sync2.compareTo(sync1), 1);
assertEquals(sync1.compareTo(sync1), 0);
sync2 = new SynchronizationRecord(theSync.getReference(), false);
assertEquals(sync1.compareTo(sync2), -1);
}
use of com.arjuna.ats.internal.jts.resources.SynchronizationRecord in project narayana by jbosstm.
the class SynchronizationRecordUnitTest method test.
@Test
public void test() throws Exception {
demosync theSync = new demosync();
SynchronizationRecord sync = new SynchronizationRecord(theSync.getReference(), false);
assertTrue(sync.contents() == theSync.getReference());
assertTrue(sync.get_uid() != Uid.nullUid());
}
Aggregations