use of com.arjuna.ats.arjuna.state.OutputBuffer in project narayana by jbosstm.
the class HornetqJournalStore method write_committed.
/**
* Write a new copy of the object's committed state.
*
* @param uid The object to work on.
* @param typeName The type of the object to work on.
* @param txData The state to write.
* @return <code>true</code> if no errors occurred, <code>false</code>
* otherwise.
* @throws ObjectStoreException if things go wrong.
*/
public boolean write_committed(Uid uid, String typeName, OutputObjectState txData) throws ObjectStoreException {
RecordInfo previousRecord = null;
try {
OutputBuffer outputBuffer = new OutputBuffer();
UidHelper.packInto(uid, outputBuffer);
outputBuffer.packString(typeName);
outputBuffer.packBytes(txData.buffer());
byte[] data = outputBuffer.buffer();
RecordInfo record = new RecordInfo(getId(uid, typeName), RECORD_TYPE, data, false, (short) 0);
previousRecord = getContentForType(typeName).putIfAbsent(uid, record);
if (previousRecord != null) {
// the packed data may have changed so updated the map with the latest data
getContentForType(typeName).replace(uid, record);
journal.appendUpdateRecord(previousRecord.id, RECORD_TYPE, data, syncWrites);
} else {
journal.appendAddRecord(record.id, RECORD_TYPE, data, syncWrites);
}
} catch (Exception e) {
if (previousRecord == null) {
// if appendAddRecord() fails, remove record from map. Leave it there if appendUpdateRecord() fails.
getContentForType(typeName).remove(uid);
}
throw new ObjectStoreException(e);
}
return true;
}
use of com.arjuna.ats.arjuna.state.OutputBuffer in project narayana by jbosstm.
the class ActionHierarchyUnitTest method test.
@Test
public void test() throws Exception {
ActionHierarchy ah = new ActionHierarchy(5);
Uid[] tx = new Uid[5];
assertEquals(ah.getDeepestActionUid(), Uid.nullUid());
for (int i = 0; i < tx.length; i++) {
tx[i] = new Uid();
ah.add(tx[i]);
}
assertEquals(ah.depth(), tx.length);
assertEquals(ah.getActionUid(0), tx[0]);
Uid deepest = new Uid();
ah.add(deepest, ActionType.TOP_LEVEL);
PrintWriter pw = new PrintWriter(System.err);
ah.print(pw);
assertEquals(ah.getDeepestActionUid(), deepest);
ActionHierarchy cp = new ActionHierarchy(ah);
assertTrue(cp.equals(ah));
cp.copy(ah);
ah.copy(ah);
assertTrue(cp.equals(ah));
OutputBuffer out = new OutputBuffer();
cp.pack(out);
InputBuffer in = new InputBuffer(out.buffer());
ah.unpack(in);
assertTrue(ah.equals(cp));
assertTrue(ah.isAncestor(deepest));
ah.forgetDeepest();
assertTrue(ah.findCommonPrefix(cp) != 0);
}
use of com.arjuna.ats.arjuna.state.OutputBuffer in project narayana by jbosstm.
the class IOStateUnitTest method testIOObjectBuffer.
@Test
public void testIOObjectBuffer() throws Exception {
PrintWriter pw = new PrintWriter(new StringWriter());
OutputBuffer obuff = new OutputBuffer(1024);
obuff.print(pw);
assertTrue(obuff.toString() != null);
OutputBuffer tobuff = new OutputBuffer(obuff);
assertTrue(tobuff.valid());
InputBuffer ibuff = new InputBuffer();
ibuff.print(pw);
InputBuffer tibuff = new InputBuffer(ibuff);
assertEquals(tibuff.valid(), false);
}
Aggregations