use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class StateManager method activate.
/**
* This operation activates an object. Activation of an object may entail
* loading its passive state from the object store and unpacking it into the
* memory resident form, or it may simply be a no-op. Full activation is
* only necessary if the object is currently marked as being PASSIVE (that
* is, the object was constructed as being of type ANDPERSISTENT with an
* existing uid and has not already been activated). Objects that are not of
* type ANDPERSISTENT or are persistent but have not yet been saved in an
* object store (so-called new persistent objects) are unaffected by this
* function. Returns false if PASSIVE object cannot be loaded from object
* store, true otherwise.
*
* @return <code>true</code> on success, <code>false</code> otherwise.
* @see com.arjuna.ats.arjuna.objectstore.ObjectStore
*/
public synchronized boolean activate(String rootName) {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("StateManager::activate( " + ((rootName != null) ? rootName : "null") + ") for object-id " + objectUid);
}
if (myType == ObjectType.NEITHER) {
return true;
}
if (currentStatus == ObjectStatus.DESTROYED)
return false;
BasicAction action = null;
int oldStatus = currentStatus;
boolean result = true;
/* assume 'succeeds' */
boolean forceAR = false;
/*
* Check if this action has logged its presence before. If not we force
* creation of an ActivationRecord so that each thread/action tree has
* an ActivationRecord in it. This allows us to passivate the object
* when the last thread has finished with it, i.e., when the last
* ActivationRecord is gone.
*/
action = BasicAction.Current();
if ((action != null) && (action.status() == ActionStatus.RUNNING)) {
synchronized (mutex) {
createLists();
if (usingActions.get(action.get_uid()) == null) {
/*
* May cause us to add parent as well as child.
*/
usingActions.put(action.get_uid(), action);
forceAR = true;
}
}
}
if (forceAR || (currentStatus == ObjectStatus.PASSIVE) || (currentStatus == ObjectStatus.PASSIVE_NEW)) {
if (loadObjectState()) {
setupStore(rootName);
}
if (currentStatus == ObjectStatus.PASSIVE) {
if (loadObjectState()) {
InputObjectState oldState = null;
try {
oldState = participantStore.read_committed(objectUid, type());
} catch (ObjectStoreException e) {
e.printStackTrace();
oldState = null;
}
if (oldState != null) {
if ((result = restore_state(oldState, ObjectType.ANDPERSISTENT))) {
currentStatus = ObjectStatus.ACTIVE;
}
oldState = null;
} else {
tsLogger.i18NLogger.warn_StateManager_2(objectUid, type());
return false;
}
} else {
if (currentStatus == ObjectStatus.PASSIVE_NEW)
currentStatus = ObjectStatus.ACTIVE_NEW;
else
currentStatus = ObjectStatus.ACTIVE;
}
} else {
if (currentStatus == ObjectStatus.PASSIVE_NEW)
currentStatus = ObjectStatus.ACTIVE_NEW;
else
currentStatus = ObjectStatus.ACTIVE;
}
if (forceAR || ((currentStatus == ObjectStatus.ACTIVE) || (currentStatus == ObjectStatus.PASSIVE_NEW)) && (action != null)) {
int arStatus = AddOutcome.AR_ADDED;
ActivationRecord ar = new ActivationRecord(oldStatus, this, action);
if ((arStatus = action.add(ar)) != AddOutcome.AR_ADDED) {
ar = null;
if (forceAR) {
synchronized (mutex) {
usingActions.remove(action.get_uid());
}
}
if (arStatus == AddOutcome.AR_REJECTED)
result = false;
} else {
/*
* We never reset activated, so we can optimise state
* loading/unloading in the case of SINGLE object model
*/
currentlyActivated = activated = true;
}
} else {
if (currentStatus == ObjectStatus.ACTIVE_NEW)
currentlyActivated = activated = true;
}
}
return result;
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class ObjectStateQuery method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) {
String uid = null;
String type = null;
for (int i = 0; i < args.length; i++) {
if (args[i].compareTo("-help") == 0) {
usage();
System.exit(0);
} else {
if (args[i].compareTo("-uid") == 0) {
uid = args[i + 1];
i++;
} else {
if (args[i].compareTo("-type") == 0) {
type = args[i + 1];
i++;
} else {
System.out.println("Unknown option " + args[i]);
usage();
System.exit(0);
}
}
}
}
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
System.out.println("Status is " + recoveryStore.currentState(new Uid(uid), type));
InputObjectState buff = new InputObjectState();
recoveryStore.allObjUids(type, buff, StateStatus.OS_UNCOMMITTED);
Uid u = UidHelper.unpackFrom(buff);
System.out.println("got " + u);
} catch (Exception e) {
System.err.println("Caught unexpected exception: " + e);
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class OtherObjectStoreAPIJMXTest method testActionStore.
@Test
public void testActionStore() throws Exception {
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
objectStoreEnvironmentBean.setLocalOSRoot("tmp");
ActionStore as = new ActionStore(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 OtherObjectStoreAPIJMXTest method testVolatileStore.
@Test
public void testVolatileStore() throws Exception {
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
objectStoreEnvironmentBean.setLocalOSRoot("tmp");
VolatileStore as = new VolatileStore(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();
InputObjectState ios = new InputObjectState();
try {
rsProxy.allObjUids("", ios);
} catch (final Exception ex) {
}
try {
assertTrue(psProxy.read_uncommitted(u, tn) == null);
} catch (final Exception ex) {
}
try {
psProxy.commit_state(u, tn);
} catch (final Exception ex) {
}
rsProxy.write_committed(u, tn, buff);
assertTrue(rsProxy.currentState(u, tn) == StateStatus.OS_COMMITTED);
rsProxy.read_committed(u, tn);
try {
assertTrue(psProxy.remove_uncommitted(u, tn));
} catch (final Exception ex) {
}
rsProxy.remove_committed(u, tn);
try {
assertTrue(rsProxy.hide_state(u, tn));
} catch (final Exception ex) {
}
try {
assertTrue(rsProxy.reveal_state(u, tn));
} catch (final Exception ex) {
}
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class OtherObjectStoreAPIJMXTest method testHashedActionStore.
@Test
public void testHashedActionStore() throws Exception {
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
objectStoreEnvironmentBean.setLocalOSRoot("tmp");
HashedActionStore as = new HashedActionStore(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));
}
}
Aggregations