use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.
the class OTM method updateTransactions.
@SuppressWarnings("unchecked")
public synchronized void updateTransactions() {
if (scanningNode != null) {
DefaultMutableTreeNode top = (DefaultMutableTreeNode) topTran.getFirstChild();
DefaultTreeModel model = (DefaultTreeModel) transactions.getModel();
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState types = new InputObjectState();
startSweep();
if (recoveryStore.allTypes(types)) {
String fullPathName = null;
boolean found = false;
try {
boolean endOfList = false;
DefaultMutableTreeNode currentNode = null;
DefaultMutableTreeNode currentRoot = top;
while (!endOfList) {
fullPathName = types.unpackString();
if (fullPathName.compareTo("") == 0)
endOfList = true;
else {
found = true;
InputObjectState uids = new InputObjectState();
String nodeName = stripName(fullPathName);
boolean added = false;
currentNode = findNode(fullPathName);
if (currentNode == null) {
currentNode = new DefaultMutableTreeNode(nodeName);
addDirectory(currentNode, fullPathName);
currentRoot.add(currentNode);
/*
* New, so update view.
*/
int[] i = new int[1];
i[0] = currentRoot.getChildCount() - 1;
model.nodesWereInserted(currentRoot, i);
added = true;
}
currentRoot = findRoot(top, currentNode);
if (added)
currentRoot.add(currentNode);
if (recoveryStore.allObjUids(fullPathName, uids)) {
Uid theUid = new Uid(Uid.nullUid());
try {
boolean endOfUids = false;
boolean first = true;
boolean haveUids = false;
while (!endOfUids) {
theUid = UidHelper.unpackFrom(uids);
if (theUid.equals(Uid.nullUid())) {
if (!haveUids) {
if (emptyDirectory(currentNode)) {
currentNode.removeAllChildren();
model.nodeChanged(currentNode);
}
}
endOfUids = true;
} else {
haveUids = true;
if (first) {
currentNode.removeAllChildren();
first = false;
}
DefaultMutableTreeNode tranID = new DefaultMutableTreeNode(theUid.stringForm());
tranID.add(new DefaultMutableTreeNode(new String("status: " + statusToString(recoveryStore.currentState(theUid, fullPathName)))));
currentNode.add(tranID);
added = true;
}
}
} catch (Exception e) {
// end of uids!
}
if (added)
model.nodeChanged(currentNode);
}
}
if (!found)
currentRoot.add(emptyTx);
}
} catch (Exception e) {
// end of list!
}
}
try {
endSweep();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
} catch (Exception e) {
System.err.println(e);
}
}
}
use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.
the class RemoveCachedTest method test.
@Test
public void test() throws IOException, ObjectStoreException {
boolean passed = true;
RecoveryStore store = new CacheStore(new ObjectStoreEnvironmentBean());
String type = "ArjunaMS/Destinations/a3d6227_dc656_3b77ce7e_2/Messages";
InputObjectState buff = new InputObjectState();
if (store.allObjUids(type, buff, StateStatus.OS_COMMITTED)) {
Uid toRemove = new Uid(Uid.nullUid());
do {
toRemove = UidHelper.unpackFrom(buff);
if (toRemove.notEquals(Uid.nullUid())) {
System.err.println("Removing " + toRemove + "\n");
if (store.remove_committed(toRemove, type))
passed = true;
else {
System.err.println("Failed for " + toRemove);
passed = false;
}
}
} while (toRemove.notEquals(Uid.nullUid()));
}
assertTrue(passed);
}
use of com.arjuna.ats.arjuna.objectstore.RecoveryStore in project narayana by jbosstm.
the class LogStoreTest method test.
@Test
public void test() {
arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
final int numberOfTransactions = 1000;
final Uid[] ids = new Uid[numberOfTransactions];
final int fakeData = 0xdeedbaaf;
final String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/Test";
for (int i = 0; i < numberOfTransactions; i++) {
OutputObjectState dummyState = new OutputObjectState();
try {
dummyState.packInt(fakeData);
ids[i] = new Uid();
recoveryStore.write_committed(ids[i], type, dummyState);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
InputObjectState ios = new InputObjectState();
boolean passed = false;
try {
if (recoveryStore.allObjUids(type, ios, StateStatus.OS_UNKNOWN)) {
Uid id = new Uid(Uid.nullUid());
int numberOfEntries = 0;
do {
try {
id = UidHelper.unpackFrom(ios);
} catch (Exception ex) {
id = Uid.nullUid();
}
if (id.notEquals(Uid.nullUid())) {
passed = true;
System.err.println("Located transaction log " + id + " in object store.");
numberOfEntries++;
boolean found = false;
for (int i = 0; i < ids.length; i++) {
if (id.equals(ids[i]))
found = true;
}
if (passed && !found) {
passed = false;
System.err.println("Found unexpected transaction!");
}
}
} while (id.notEquals(Uid.nullUid()));
if ((numberOfEntries != ids.length) && passed) {
passed = false;
System.err.println("Expected " + ids.length + " and got " + numberOfEntries);
}
}
} catch (final Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
use of com.arjuna.ats.arjuna.objectstore.RecoveryStore 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.objectstore.RecoveryStore 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;
}
Aggregations