use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class XATerminatorImple method doRecover.
/**
* Return a list of indoubt transactions. This may include those
* transactions that are currently in-flight and running 2PC and do not need
* recovery invoked on them.
*
* @param nodeName
* Only recover transactions for this node (unless set to NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES)
* @throws XAException
* thrown if any error occurs.
* @return a list of potentially indoubt transactions or <code>null</code>.
*/
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException {
/*
* Requires going through the objectstore for the states of imported
* transactions. Our own crash recovery takes care of transactions
* imported via CORBA, Web Services etc.
*/
Xid[] indoubt = null;
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState states = new InputObjectState();
if (recoveryStore.allObjUids(SubordinateAtomicAction.getType(), states) && (states.notempty())) {
Stack<Xid> values = new Stack<Xid>();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
ex.printStackTrace();
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
if (parentNodeName != null) {
SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
XidImple loadedXid = (XidImple) saa.getXid();
if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
if ((loadedXidSubordinateNodeName == null && loadedXidSubordinateNodeName == TxControl.getXANodeName()) || loadedXidSubordinateNodeName.equals(TxControl.getXANodeName())) {
if (parentNodeName.equals(saa.getParentNodeName())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + saa);
}
// TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
values.push(loadedXid);
}
}
}
} else if (xid == null) {
TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx.baseXid());
} else {
SubordinateAtomicAction saa = new SubordinateAtomicAction(uid, true);
XidImple loadedXid = (XidImple) saa.getXid();
if (loadedXid != null && loadedXid.getFormatId() == XATxConverter.FORMAT_ID) {
String loadedXidSubordinateNodeName = XATxConverter.getSubordinateNodeName(loadedXid.getXID());
if (XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID()).equals(loadedXidSubordinateNodeName)) {
if (Arrays.equals(loadedXid.getGlobalTransactionId(), xid.getGlobalTransactionId())) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("Found record for " + saa);
}
TransactionImple tx = (TransactionImple) SubordinationManager.getTransactionImporter().recoverTransaction(uid);
values.push(loadedXid);
}
}
}
}
} else
finished = true;
} while (!finished);
if (values.size() > 0) {
int index = 0;
indoubt = new Xid[values.size()];
while (!values.empty()) {
indoubt[index] = values.pop();
index++;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return indoubt;
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class XAResourceRecord method loadState.
private final boolean loadState() {
setObjectStore();
InputObjectState os = null;
try {
os = _participantStore.read_committed(_theUid, type());
} catch (Exception e) {
jtaxLogger.i18NLogger.warn_jtax_resources_jts_orbspecific_loadstateread(e);
os = null;
}
if (os != null) {
_valid = restoreState(os);
os = null;
} else
_valid = false;
return _valid;
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class XATerminatorImple method doRecover.
/**
* <p>
* Recovering /JCA section of object store.
* The filtering functionality on xid or parentNodeName is not permitted and throws {@link NotSupportedException}.<br>
* Expected to be called only with null parameters <code>doRecover(null, null)</code>
*
* @param xid has to be null
* @param parentNodeName has to be null
* @return array of subordinate recovered xids
* @throws XAException if recovery operation fails for the XA protocol reason
* @throws NotSupportedException if not null params are passes as method parameters
*/
@Override
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException, NotSupportedException {
if (xid != null || parentNodeName != null)
throw new NotSupportedException("doRecover method works only with null arguments");
Xid[] indoubt = null;
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState states = new InputObjectState();
// only look in the JCA section of the object store
if (recoveryStore.allObjUids(ServerTransaction.getType(), states) && (states.notempty())) {
Stack<Transaction> values = new Stack<Transaction>();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
jtsLogger.i18NLogger.info_fail_to_read_subordinate_uid(recoveryStore, states, ex);
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
Transaction tx = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx);
} else
finished = true;
} while (!finished);
if (values.size() > 0) {
int index = 0;
indoubt = new Xid[values.size()];
while (!values.empty()) {
TransactionImple id = (TransactionImple) values.pop();
indoubt[index] = id.baseXid();
index++;
}
}
}
} catch (Exception ex) {
jtsLogger.i18NLogger.info_fail_to_dorecover(xid, parentNodeName, ex);
}
return indoubt;
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class XAResourceRecordWrappingPluginImpl method initialize.
private void initialize() throws ObjectStoreException, IOException {
if (this.nodeIdentifier == null) {
synchronized (this) {
// null in case of race condition
if (this.nodeIdentifier == null) {
this.nodeIdentifier = TxControl.getXANodeName();
this.eisNameStore = StoreManager.getEISNameStore();
InputObjectState states = new InputObjectState();
int keyMax = 0;
boolean allObjUids = eisNameStore.allObjUids("EISNAME", states);
while (states.notempty()) {
Uid uid = UidHelper.unpackFrom(states);
if (uid.equals(Uid.nullUid())) {
break;
} else {
InputObjectState oState = eisNameStore.read_committed(uid, "EISNAME");
String nodeName = oState.unpackString();
if (nodeName.equals(nodeIdentifier)) {
Integer key = oState.unpackInt();
String jndiName = oState.unpackString();
keyToName.put(key, jndiName);
nameToKey.put(jndiName, key);
if (key > keyMax) {
keyMax = key;
}
} else {
// logger warn that we are using a new node
}
}
}
nextKey.set(keyMax + 1);
}
}
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class ComplexLockManagerProxyUnitTest method testSaveRestore.
public void testSaveRestore() {
BasicLockable obj = new BasicLockable();
LockManagerProxy<BasicLockable> proxy = new LockManagerProxy<BasicLockable>(obj);
OutputObjectState os = new OutputObjectState();
assertTrue(proxy.save_state(os, ObjectType.RECOVERABLE));
obj._saved = 4567;
// make sure it's ignored by save/restore.
obj._isState = 0;
InputObjectState ios = new InputObjectState(os);
assertTrue(proxy.restore_state(ios, ObjectType.RECOVERABLE));
assertEquals(obj._saved, 1234);
assertEquals(obj._isState, 0);
}
Aggregations