use of org.omg.CosTransactions.SubtransactionAwareResource in project narayana by jbosstm.
the class ArjunaTransactionImple method register_resource.
/**
* Resources are only registered with the current transaction, whereas
* subtransaction aware resources are registered with their parents when the
* current transaction ends.
*/
public RecoveryCoordinator register_resource(Resource r) throws SystemException, Inactive {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource ( " + r + " ) - called for " + get_uid());
}
if (r == null)
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
currentStatus = determineStatus(this);
if (currentStatus != Status.StatusActive) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource - transaction not active: " + Utility.stringStatus(currentStatus));
}
if (currentStatus == Status.StatusMarkedRollback) {
throw new TRANSACTION_ROLLEDBACK(ExceptionCodes.MARKED_ROLLEDBACK, CompletionStatus.COMPLETED_NO);
} else
throw new Inactive();
}
AbstractRecord corbaRec = null;
BasicAction registerIn = this;
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple " + get_uid() + " ::register_resource: ");
}
//
// Creation of recovery coordinator (DBI)
//
//
// Pack the params:
// [0] = Transaction* this
//
int index = 0;
Object[] params = new Object[10];
params[index++] = this;
RecoveryCoordinator recoveryCoordinator = null;
Uid recoveryCoordinatorUid = null;
try {
recoveryCoordinator = RecoveryCreator.createRecoveryCoordinator(r, params);
if (recoveryCoordinator == null)
throw new BAD_OPERATION("RecoveryCoordinator " + jtsLogger.i18NLogger.get_orbspecific_coordinator_rcnotcreated());
} catch (NO_IMPLEMENT ex) {
/*
* This is legal, and is meant to show that this ORB or
* configuration simply doesn't support crash recovery.
*/
recoveryCoordinator = null;
} catch (SystemException e) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_rccreate(get_uid(), e);
try {
rollback_only();
} catch (Inactive ex1) {
} catch (SystemException ex2) {
jtsLogger.i18NLogger.warn_orbspecific_coordinator_rbofail("ArjunaTransactionImple.register_resource", get_uid(), ex2);
throw ex2;
}
throw e;
}
if (recoveryCoordinator != null) {
//
// We got a RecoveryCoordinator, so unpack the other return values:
// [0] = RecoveryCoordinator Uid*
//
index = 0;
recoveryCoordinatorUid = (Uid) params[index++];
} else {
//
// We didn't get a RecoveryCoordinator, so we don't assume that
// the other return values have been populated.
//
recoveryCoordinatorUid = Uid.nullUid();
}
try {
SubtransactionAwareResource staResource = org.omg.CosTransactions.SubtransactionAwareResourceHelper.narrow(r);
if (staResource != null) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " - subtransaction aware resource: YES");
}
/*
* If here the narrow was ok so we have a subtran aware
* resource.
*/
Coordinator coord = null;
if (parentHandle != null) {
/*
* If we are a SubTranResource then we get registered with
* the current transaction and its parents upon completion.
* The first parameter to the record indicates whether we
* should be propagated (registered) with the parent
* transaction.
*/
coord = parentHandle.get_coordinator();
}
corbaRec = createOTSRecord(true, r, coord, recoveryCoordinatorUid);
coord = null;
staResource = null;
} else
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (BAD_PARAM ex) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " - subtransaction aware resource: NO");
}
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple " + get_uid() + " ::register_resource: Simple resource - " + ex);
}
corbaRec = createOTSRecord(true, r, null, recoveryCoordinatorUid);
} catch (Unavailable e1) {
throw new Inactive();
} catch (SystemException e2) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : catch (SystemException) - " + e2);
}
throw e2;
} catch (Exception e3) {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : catch (...) - " + e3);
}
throw new UNKNOWN(e3.toString(), ExceptionCodes.UNKNOWN_EXCEPTION, CompletionStatus.COMPLETED_NO);
}
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : try end");
}
if (registerIn.add(corbaRec) != AddOutcome.AR_ADDED) {
corbaRec = null;
throw new INVALID_TRANSACTION(ExceptionCodes.ADD_FAILED, CompletionStatus.COMPLETED_NO);
} else {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ArjunaTransactionImple::register_resource for " + get_uid() + " : resource registered");
}
}
return recoveryCoordinator;
}
use of org.omg.CosTransactions.SubtransactionAwareResource in project narayana by jbosstm.
the class ResourceRecord method nestedPrepare.
/**
* OTS does not use nested prepare at all!
* However, to make nested commit/abort clean we do commit_subtransaction
* here.
* Note that we only get a prepare from Arjuna if the action is to be
* committed so this is safe in Arjuna terms.
*/
public int nestedPrepare() {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ResourceRecord::nestedPrepare() for " + order());
}
int o = TwoPhaseOutcome.ONE_PHASE_ERROR;
SubtransactionAwareResource staResource = null;
try {
if (_committed)
return TwoPhaseOutcome.PREPARE_OK;
else
_committed = true;
staResource = org.omg.CosTransactions.SubtransactionAwareResourceHelper.narrow(resourceHandle());
if (staResource == null)
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (Exception e) {
/*
* Not subtran aware resource, so return PREPARE_OK.
* Resource will get invocations at top-level only.
*/
o = TwoPhaseOutcome.PREPARE_OK;
}
if (staResource != null) {
try {
staResource.commit_subtransaction(_parentCoordHandle);
o = TwoPhaseOutcome.PREPARE_OK;
staResource = null;
} catch (Exception e) {
o = TwoPhaseOutcome.ONE_PHASE_ERROR;
}
}
/*
* Now release the parent as it is about to be destroyed
* anyway.
*/
_parentCoordHandle = null;
return o;
}
use of org.omg.CosTransactions.SubtransactionAwareResource in project narayana by jbosstm.
the class ResourceRecord method nestedAbort.
/**
* General nesting rules:
*
* Only SubtransactionAware resources get registered with nested actions.
* The ResourceRecord creator is assumed to ensure that plain Resources
* are only registered with the appropriate top level action.
*
* That said the _propagateRecord flag ensures that resources registered
* via register_subtran only take part in the action they where registered
* in after which they are dropped
*/
public int nestedAbort() {
if (jtsLogger.logger.isTraceEnabled()) {
jtsLogger.logger.trace("ResourceRecord::nestedAbort() for " + order());
}
/*
* We shouldn't need to check committed since aborted nested actions
* will drop these resources.
*/
SubtransactionAwareResource staResource = null;
int o = TwoPhaseOutcome.FINISH_ERROR;
try {
/*
* Must be an staResource to get here.
*/
staResource = org.omg.CosTransactions.SubtransactionAwareResourceHelper.narrow(resourceHandle());
if (staResource == null)
throw new BAD_PARAM(0, CompletionStatus.COMPLETED_NO);
} catch (Exception exEnv) {
// not a sub tran resource, so ignore;
o = TwoPhaseOutcome.FINISH_OK;
}
if (staResource != null) {
try {
staResource.rollback_subtransaction();
o = TwoPhaseOutcome.FINISH_OK;
} catch (Exception e) {
o = TwoPhaseOutcome.FINISH_ERROR;
}
staResource = null;
}
/*
* Now release the parent as it is about to be destroyed
* anyway.
*
* The parent may have already been released if abort is
* being called because commit failed.
*/
_parentCoordHandle = null;
return o;
}
use of org.omg.CosTransactions.SubtransactionAwareResource in project narayana by jbosstm.
the class SingleSubtranAwareResourceRegistration method work.
public void work() throws PerfTestException {
try {
/**
* Retrieve ORB and OA references
*/
ORB orb = ORB.getInstance(PerformanceFramework.ORB_INSTANCE_NAME);
OA oa = OA.getRootOA(orb);
Control control = OTSManager.get_current().get_control();
Coordinator coordinator = control.get_coordinator();
DemoSubTranResource resource = new DemoSubTranResource();
oa.objectIsReady(resource);
SubtransactionAwareResource res = SubtransactionAwareResourceHelper.narrow(oa.corbaReference(resource));
coordinator.register_resource(res);
} catch (Exception e) {
throw new PerfTestException();
}
}
Aggregations