use of com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord 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.internal.arjuna.abstractrecords.ActivationRecord in project narayana by jbosstm.
the class RecordListUnitTest method test.
@Test
public void test() throws Exception {
RecordList rl = new RecordList();
DisposeRecord dr = new DisposeRecord();
rl.insert(dr);
assertEquals(rl.getFront(), dr);
rl.insert(dr);
assertEquals(rl.getRear(), dr);
RecordList copy = new RecordList(rl);
ActivationRecord ar = new ActivationRecord();
rl.insert(ar);
rl.print(new PrintWriter(new ByteArrayOutputStream()));
assertTrue(rl.toString() != null);
assertEquals(rl.getNext(dr), null);
assertTrue(rl.peekFront() != null);
assertTrue(rl.peekRear() != null);
assertEquals(rl.peekNext(dr), null);
assertTrue(rl.remove(dr));
}
use of com.arjuna.ats.internal.arjuna.abstractrecords.ActivationRecord in project narayana by jbosstm.
the class ActivationRecordUnitTest method test.
@Test
public void test() {
AtomicAction A = new AtomicAction();
AtomicAction B = new AtomicAction();
A.begin();
B.begin();
ActivationRecord cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
assertFalse(cr.propagateOnAbort());
assertTrue(cr.propagateOnCommit());
assertEquals(cr.typeIs(), RecordType.ACTIVATION);
assertTrue(cr.type() != null);
assertEquals(cr.doSave(), false);
assertEquals((Integer) cr.value(), new Integer(ObjectType.ANDPERSISTENT));
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), B);
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
B.abort();
cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
cr = new ActivationRecord(ObjectType.ANDPERSISTENT, new ExtendedObject(), A);
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new ActivationRecord();
cr.merge(new ActivationRecord());
cr.alter(new ActivationRecord());
assertTrue(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
A.abort();
}
Aggregations