use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class OtherObjectStoreAPIJMXTest method testNullActionStore.
@Test
public void testNullActionStore() throws Exception {
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
objectStoreEnvironmentBean.setLocalOSRoot("tmp");
NullActionStore as = new NullActionStore(objectStoreEnvironmentBean);
final OutputObjectState buff = new OutputObjectState();
final String tn = "/StateManager/junit";
createMBeans(as, as);
for (int i = 0; i < 10; i++) {
Uid u = new Uid();
psProxy.write_uncommitted(u, tn, buff);
psProxy.commit_state(u, tn);
assertTrue(rsProxy.currentState(u, tn) != StateStatus.OS_UNCOMMITTED);
InputObjectState ios = new InputObjectState();
rsProxy.allObjUids("", ios);
assertTrue(psProxy.read_uncommitted(u, tn) == null);
rsProxy.write_committed(u, tn, buff);
rsProxy.read_committed(u, tn);
assertTrue(!psProxy.remove_uncommitted(u, tn));
rsProxy.remove_committed(u, tn);
assertTrue(!rsProxy.hide_state(u, tn));
assertTrue(!rsProxy.reveal_state(u, tn));
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class LockManager method loadState.
/*
* Lock and load the concurrency control state. First we grab the semaphore
* to ensure exclusive access and then we build the held lock list by
* retrieving the locks from the lock repository. If there is only one
* server we do not bother doing this since all the locks can stay in the
* server's memory. This is yet another consequence of not having
* multi-threaded servers. Does not require synchronized since it can only
* be called from other synchronized methods.
*/
/*
* Return to 'protected final boolean' if we address https://issues.jboss.org/browse/JBTM-2399
*/
protected boolean loadState() {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::loadState()");
}
if (super.objectModel == ObjectModel.SINGLE) {
stateLoaded = true;
return true;
} else {
InputObjectState S = null;
if ((systemKey == null) && !initialise()) {
return false;
/* init failed */
}
if ((mutex == null) || (!mutex.tryLock())) {
return false;
}
stateLoaded = false;
objectLocked = true;
try {
S = lockStore.read_state(get_uid(), type());
if (S != null) {
Uid u = null;
/*
* avoid system calls in Uid
* creation
*/
Lock current = null;
int count = 0;
try {
count = S.unpackInt();
boolean cleanLoad = true;
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::loadState() loading " + count + " lock(s)");
}
for (int i = 0; (i < count) && cleanLoad; i++) {
try {
u = UidHelper.unpackFrom(S);
current = new Lock(u);
if (current != null) {
if (current.restore_state(S, ObjectType.ANDPERSISTENT)) {
locksHeld.push(current);
} else {
current = null;
cleanLoad = false;
}
} else {
cleanLoad = false;
}
} catch (IOException e) {
cleanLoad = false;
}
}
if (cleanLoad)
stateLoaded = true;
else {
while ((current = locksHeld.pop()) != null) current = null;
}
} catch (IOException e) {
}
S = null;
} else
stateLoaded = true;
} catch (LockStoreException e) {
txojLogger.logger.warn(e);
}
}
if (!stateLoaded) {
if (// means object model != SINGLE
mutex != null) {
// and exit mutual exclusion
mutex.unlock();
}
objectLocked = false;
}
return stateLoaded;
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class TORecoveryModule method periodicWorkFirstPass.
public void periodicWorkFirstPass() {
if (txojLogger.logger.isDebugEnabled()) {
txojLogger.logger.debug("TORecoveryModule - first pass");
}
// Build a hashtable of uncommitted transactional objects
_uncommittedTOTable = new Hashtable();
try {
InputObjectState types = new InputObjectState();
// find all the types of transactional object (in this ObjectStore)
if (_objectStore.allTypes(types)) {
String theName = null;
try {
boolean endOfList = false;
while (!endOfList) {
// extract a type
theName = types.unpackString();
if (theName.compareTo("") == 0)
endOfList = true;
else {
InputObjectState uids = new InputObjectState();
// entry in the object store
if (_objectStore.allObjUids(theName, uids, StateStatus.OS_UNCOMMITTED)) {
Uid theUid = null;
try {
boolean endOfUids = false;
while (!endOfUids) {
// extract a uid
theUid = UidHelper.unpackFrom(uids);
if (theUid.equals(Uid.nullUid()))
endOfUids = true;
else {
String newTypeString = new String(theName);
Uid newUid = new Uid(theUid);
_uncommittedTOTable.put(newUid, newTypeString);
if (txojLogger.logger.isDebugEnabled()) {
txojLogger.logger.debug("TO currently uncommitted " + newUid + " is a " + newTypeString);
}
}
}
} catch (Exception e) {
// end of uids!
}
}
}
}
} catch (IOException ex) {
// nothing there.
} catch (Exception e) {
txojLogger.i18NLogger.warn_recovery_TORecoveryModule_5(e);
}
}
} catch (Exception e) {
txojLogger.i18NLogger.warn_recovery_TORecoveryModule_5(e);
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class PersistenceTest method test.
@Test
public void test() throws Throwable {
ParticipantStore store = StoreManager.getParticipantStore();
OutputObjectState state = new OutputObjectState();
Uid u = new Uid();
assertTrue(store.write_committed(u, "/StateManager/LockManager/foo", state));
InputObjectState inputState = store.read_committed(u, "/StateManager/LockManager/foo");
assertNotNull(inputState);
store.stop();
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class IOStateUnitTest method testIOObjectState.
@Test
public void testIOObjectState() throws Exception {
OutputObjectState oos = new OutputObjectState(new Uid(), "");
oos.packBoolean(true);
oos.packByte((byte) 0);
oos.packChar('a');
oos.packDouble(1.0);
oos.packFloat((float) 1.0);
oos.packInt(1);
oos.packLong(1234);
oos.packShort((short) 10);
oos.packString("test");
assertTrue(oos.valid());
PrintWriter pw = new PrintWriter(new StringWriter());
oos.print(pw);
assertTrue(oos.length() != 0);
assertTrue(oos.notempty());
assertTrue(oos.stateUid() != Uid.nullUid());
assertTrue(oos.buffer() != null);
assertTrue(oos.size() > 0);
assertTrue(oos.type() != null);
OutputObjectState temp = new OutputObjectState(oos);
assertTrue(temp.toString() != null);
InputObjectState ios = new InputObjectState(oos);
assertTrue(ios.buffer() != null);
assertTrue(ios.length() > 0);
assertTrue(ios.notempty());
assertTrue(ios.size() > 0);
assertTrue(ios.stateUid() != Uid.nullUid());
assertTrue(ios.valid());
ios.print(pw);
InputObjectState is = new InputObjectState(ios);
assertTrue(is.toString() != null);
assertTrue(ios.unpackBoolean());
assertEquals(ios.unpackByte(), (byte) 0);
assertEquals(ios.unpackChar(), 'a');
assertTrue(ios.unpackDouble() == 1.0);
assertTrue(ios.unpackFloat() == (float) 1.0);
assertEquals(ios.unpackInt(), 1);
assertEquals(ios.unpackLong(), 1234);
assertEquals(ios.unpackShort(), (short) 10);
assertEquals(ios.unpackString(), "test");
InputObjectState c = new InputObjectState();
OutputObjectState buff = new OutputObjectState();
OutputObjectState o = new OutputObjectState();
Uid u = new Uid();
buff.packString("foobar");
UidHelper.packInto(u, buff);
buff.packInto(o);
InputBuffer ibuff = new InputBuffer(o.buffer());
c.copy(ios);
ios.unpackFrom(ibuff);
ios.copyFrom(new OutputObjectState());
assertTrue(ios.toString() != null);
oos.reset();
oos.rewrite();
oos.packInto(new OutputObjectState());
oos.copy(new OutputObjectState());
assertTrue(oos.toString() != null);
temp = new OutputObjectState(new Uid(), "", null);
assertFalse(temp.valid());
}
Aggregations