use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.
the class JavaIdlRCDefaultServant method replay_completion.
public Status replay_completion(Resource res) throws SystemException, NotPrepared {
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("JavaIdlRCDefaultServant::replay_completion)");
}
try {
// Begin New
org.omg.CORBA.Object obj = _ourOrb.resolve_initial_references("POACurrent");
org.omg.PortableServer.Current poa_current = org.omg.PortableServer.CurrentHelper.narrow(obj);
byte[] objectId = poa_current.get_object_id();
// End New
String objectIdString = new String(objectId);
String poaName = poa_current.get_POA().the_name();
if (objectIdString.startsWith(poaName)) {
// strip off the POA name prefix from the object name - the remainder encodes our Uids
int index = poaName.length();
if (objectIdString.length() > index)
index += 1;
objectIdString = objectIdString.substring(index);
}
// convert that to the structured id
RecoveryCoordinatorId recovCoId = RecoveryCoordinatorId.reconstruct(objectIdString);
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("JavaIdlDefaultServant replay_completion for Id " + recovCoId);
}
// and do the real replay
return GenericRecoveryCoordinator.replay_completion(recovCoId, res);
}/**
*/
catch (NotPrepared exp) {
throw exp;
}/**/
catch (Exception ex) {
jtsLogger.i18NLogger.warn_orbspecific_jacorb_recoverycoordinators_JacOrbRCDefaultServant_3(ex);
return Status.StatusUnknown;
}
}
use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.
the class JacOrbRCDefaultServant method replay_completion.
public Status replay_completion(Resource res) throws SystemException, NotPrepared {
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("JacOrbDefaultServant::replay_completion)");
}
try {
// Begin New
org.omg.CORBA.Object obj = _ourOrb.resolve_initial_references("POACurrent");
org.omg.PortableServer.Current poa_current = org.omg.PortableServer.CurrentHelper.narrow(obj);
byte[] objectId = poa_current.get_object_id();
// End New
String objectIdString = new String(objectId, StandardCharsets.UTF_8);
// convert that to the structured id
RecoveryCoordinatorId recovCoId = RecoveryCoordinatorId.reconstruct(objectIdString);
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("JacOrbDefaultServant replay_completion for Id " + recovCoId);
}
// and do the real replay
return GenericRecoveryCoordinator.replay_completion(recovCoId, res);
}/**
*/
catch (NotPrepared exp) {
throw exp;
}/**/
catch (Exception ex) {
jtsLogger.i18NLogger.warn_orbspecific_jacorb_recoverycoordinators_JacOrbRCDefaultServant_3(ex);
return Status.StatusUnknown;
}
}
use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.
the class GenericRecoveryCoordinator method replay_completion.
/**
* Respond to a replay_completion request for the RecoveryCoordinator
* identified by parameter id.
*/
protected static Status replay_completion(RecoveryCoordinatorId id, Resource res) throws SystemException, NotPrepared {
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("GenericRecoveryCoordinator(" + id._RCUid + ").replay_completion(" + (res != null ? "resource supplied)" : "null resource)"));
}
Status currentStatus = Status.StatusUnknown;
/*
* First check to see if the transaction is active by asking the
* per-process contact.
* If alive, return the status reported by the
* transaction. If not alive then try and recover the
* transaction from the intentions list.
*/
boolean transactionActive = true;
try {
currentStatus = get_status(id._actionUid, id._originalProcessUid);
} catch (Inactive e) {
// original process is dead.
transactionActive = false;
}
if (currentStatus == Status.StatusNoTransaction) {
/*
* There is no intentions list, so the transaction either
* committed or rolled back. However, this routine is only
* ever called by replay_completion, which means that there
* is a resource (hopefully one which was participating in
* the transaction) that is in doubt as to the
* transaction's outcome. If the transaction had committed,
* then this resource would know of the outcome. Therefore,
* it must have rolled back!
*/
/*
* Unfortunately the last statement is wrong. There is a timing
* issue here: the resource recovery may be doing an upcall while
* the downcall (from coordinator recovery) is going on and
* removing the log. What can then happen is that a resource may
* see a commit folled by a rollback.
*/
currentStatus = Status.StatusRolledBack;
}
if (!transactionActive) {
// original process is dead, so reasonable for us to try to
// recover
/*
* The RecoveredTransactionReplayer is a threaded object
* so we can get the status and return it while the
* replayer does the phase 2 commit in a new thread.
*/
String tranType = ((id._isServerTransaction) ? ServerTransaction.typeName() : ArjunaTransactionImple.typeName());
try {
if (id._isServerTransaction && (StoreManager.getRecoveryStore().currentState(id._actionUid, ServerTransaction.typeName() + "/JCA") != StateStatus.OS_UNKNOWN)) {
tranType = tranType + "/JCA";
}
} catch (ObjectStoreException e) {
// Can't read store
}
com.arjuna.ats.internal.jts.recovery.transactions.RecoveredTransactionReplayer replayer = new com.arjuna.ats.internal.jts.recovery.transactions.RecoveredTransactionReplayer(id._actionUid, tranType);
// this will cause the activatation attempt
currentStatus = replayer.getStatus();
if ((replayer.getRecoveryStatus() != com.arjuna.ats.internal.jts.recovery.transactions.RecoveryStatus.ACTIVATE_FAILED) && (res != null)) {
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("GenericRecoveryCoordinator - swapping Resource for RC " + id._RCUid);
}
replayer.swapResource(id._RCUid, res);
}
if (replayer.getRecoveryStatus() != com.arjuna.ats.internal.jts.recovery.transactions.RecoveryStatus.ACTIVATE_FAILED) {
replayer.replayPhase2();
} else {
replayer.tidyup();
/*
* The transaction didn't activate so we have a
* rollback situation but we can't rollback the
* resource that we have been given through the
* intentions list but we can issue rollback
* directly. This is configurable through the System
* properties.
*/
currentStatus = Status.StatusRolledBack;
}
}
if (currentStatus == Status.StatusRolledBack) {
if (_issueRecoveryRollback) {
ResourceCompletor resourceCompletor = new ResourceCompletor(res, ResourceCompletor.ROLLBACK);
resourceCompletor.start();
}
}
if (currentStatus == Status.StatusActive)
throw new NotPrepared();
return currentStatus;
}
use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.
the class RecoveredServerTransaction method getStatusFromParent.
private Status getStatusFromParent() {
org.omg.CosTransactions.Status theStatus = org.omg.CosTransactions.Status.StatusUnknown;
// This variable is applied with Orbix
int not_exist_count;
if ((super._recoveryCoordinator != null) && (get_status() == org.omg.CosTransactions.Status.StatusPrepared)) {
ServerControl sc = new ServerControl((ServerTransaction) this);
ServerRecoveryTopLevelAction tla = new ServerRecoveryTopLevelAction(sc);
if (tla.valid()) {
try {
theStatus = super._recoveryCoordinator.replay_completion(tla.getReference());
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("RecoveredServerTransaction.getStatusFromParent - replay_completion status = " + Utility.stringStatus(theStatus));
}
} catch (TRANSIENT ex_trans) {
/*
* A failure that might not occur again if the request is retried. Not definite.
*/
jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_10(get_uid());
theStatus = Status.StatusUnknown;
}// What here what should be done for Orbix2000
catch (OBJECT_NOT_EXIST ex) {
// i believe this state should be notran - ots explicitly
// objnotexist is
// rollback
theStatus = org.omg.CosTransactions.Status.StatusRolledBack;
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("RecoveredServerTransaction.getStatusFromParent -" + " replay_completion got object_not_exist = " + Utility.stringStatus(theStatus));
}
} catch (NotPrepared ex1) {
jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_12();
theStatus = Status.StatusActive;
} catch (Exception e) {
// Unknown error, so better to do nothing at this stage.
jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_13(e);
}
} else {
jtsLogger.i18NLogger.warn_recovery_transactions_RecoveredServerTransaction_14(get_uid());
}
// Make sure we "delete" these objects when we are finished
// with them or there will be a memory leak. If they are deleted
// "early", and the root coordinator needs them then it will find
// them unavailable, and will have to retry recovery later.
sc = null;
tla = null;
} else {
if (jtsLogger.logger.isDebugEnabled()) {
jtsLogger.logger.debug("RecoveredServerTransaction:getStatusFromParent - " + "no recovcoord or status not prepared");
}
}
return theStatus;
}
use of org.omg.CosTransactions.NotPrepared in project narayana by jbosstm.
the class RCTest method test.
@Test
public void test() {
boolean shouldCommit = true;
boolean passed = false;
Coordinator coord = null;
ORB myORB = null;
RootOA myOA = null;
try {
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
CurrentImple current = OTSImpleManager.current();
AtomicResource aImpl = new AtomicResource(shouldCommit);
Resource atomicObject = aImpl.getReference();
System.out.println("beginning top-level transaction.");
current.begin();
Control myControl = current.get_control();
assertNotNull(myControl);
System.out.println("getting coordinator");
coord = myControl.get_coordinator();
myControl = null;
System.out.println("registering resources.");
RecoveryCoordinator rc = null;
try {
rc = coord.register_resource(atomicObject);
} catch (Exception ex) {
fail("Failed to register resources: " + ex);
ex.printStackTrace();
}
if (rc == null)
System.out.println("No recovery coordinator reference.");
else {
Status s = Status.StatusUnknown;
try {
System.out.println("Attempting to use recovery coordinator.");
s = rc.replay_completion(atomicObject);
} catch (NotPrepared e) {
s = Status.StatusActive;
} catch (Exception ex) {
fail("Caught: " + ex);
ex.printStackTrace();
}
System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
if (s == Status.StatusActive)
passed = true;
}
System.out.println("committing top-level transaction.");
if (shouldCommit)
current.commit(true);
else
current.rollback();
if (rc == null)
System.out.println("No recovery coordinator reference.");
else {
Status s = Status.StatusUnknown;
try {
System.out.println("Attempting to use recovery coordinator.");
s = rc.replay_completion(atomicObject);
} catch (NotPrepared e) {
s = Status.StatusActive;
} catch (Exception ex) {
fail("Caught: " + ex);
}
System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
if (passed && (s == Status.StatusRolledBack))
passed = true;
else
passed = false;
}
} catch (TRANSACTION_ROLLEDBACK e1) {
System.out.println("\nTransaction RolledBack exception");
} catch (HeuristicMixed e2) {
System.out.println("\nTransaction HeuristicMixed exception");
} catch (HeuristicHazard e3) {
System.out.println("\nTransaction HeuristicHazard exception");
} catch (Exception e4) {
System.out.println("Caught unexpected exception: " + e4);
}
System.out.println("Trying to determing final transaction outcome.");
org.omg.CosTransactions.Status status = Status.StatusUnknown;
try {
if (coord != null) {
status = coord.get_status();
coord = null;
} else
System.out.println("\nCould not determine action status.");
} catch (SystemException ex1) {
// assume invalid reference - tx may have been garbage collected
} catch (Exception e5) {
System.out.println("Caught unexpected exception:" + e5);
}
System.out.println("\nFinal action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
assertTrue(passed);
myOA.destroy();
myORB.shutdown();
}
Aggregations