Class AbstractRecord
- java.lang.Object
-
- com.arjuna.ats.arjuna.StateManager
-
- com.arjuna.ats.arjuna.coordinator.AbstractRecord
-
public abstract class AbstractRecord extends StateManager
Abstract Record Class This class provides an abstract template that defines the interface that the atomic action system uses to notify objects that various state transitions have occurred as the 2PC protocol executes. Record types derived from this class manage certain properties of objects such as recovery information, concurrency control information etc, and all must redefine the operations defined here as abstract to take appropriate action. Many functions are declared pure virtual to force a definition to occur in any derived class. These are currently all functions dealing with atomic action coordination as well as the following list management functions: typeIs: returns the record type of the instance. This is one of the values of the enumerated type Record_type value: Some arbitrary value associated with the record instance merge: Used when two records need to merge together. Currently this is only used by CadaverRecords to merge information from PersistenceRecords shouldAdd: returns TRUE is the record should be added to the list FALSE if it should be discarded shouldMerge: returns TRUE is the two records should be merged into a single record, FALSE if it should be discarded shouldReplace: returns TRUE if the record should replace an existing one, FALSE otherwise.- Since:
- 1.0.
- Version:
- $Id: AbstractRecord.java 2342 2006-03-30 13:06:17Z $
- Author:
- Mark Little (mark@arjuna.com)
-
-
Field Summary
-
Fields inherited from class com.arjuna.ats.arjuna.StateManager
modifyingActions, objectModel, objectUid, usingActions
-
-
Constructor Summary
Constructors Modifier Constructor Description AbstractRecord()Creates a 'blank' abstract record.protectedAbstractRecord(Uid storeUid)Create a new instance with the specified paramaters.protectedAbstractRecord(Uid storeUid, String objType, int otype)Create a new instance with the specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidalter(AbstractRecord a)Alter the current record with the one presented.voidclearHeuristicDecision()Clearing the heuristic state on the resource.static AbstractRecordcreate(int type)booleandoSave()Should this record be saved in the intentions list? If the record is saved, then it may be recovered later in the event of a failure.booleanequals(AbstractRecord ar)Determine if two records are equal in that both are the same type and have the same order value (determined via 'order()').booleanforgetHeuristic()Forget any heuristic outcome which this implementation may have produced.protected AbstractRecordgetNext()protected AbstractRecordgetPrevious()These few functions are link manipulation primitives used by the RecordList processing software to chain instances together.StringgetTypeOfObject()Return the type of the abstract record.booleangreaterThan(AbstractRecord ar)Determine if two records are greater than in that both are the same type and their Uids are greater than.booleanisPermittedTopLevelOnePhaseCommit()Defines if the participant record permits the use of the one phase commit optimization.booleanlessThan(AbstractRecord ar)Determine if two records are less than in that both are the same type and their Uids are less than.abstract voidmerge(AbstractRecord a)Merge the current record with the one presented.abstract intnestedAbort()A rollback of a nested transaction has occurred.intnestedCleanup()Cleanup is called if a nested is detected to be an orphan.abstract intnestedCommit()A commit of a nested transaction has occurred.intnestedOnePhaseCommit()Perform a nested one phase commit.abstract intnestedPrepare()A prepare for a nested transaction has occurred.Uidorder()Return the Uid of this abstract record so that it can be ordered in the intentions list.voidprint(PrintWriter strm)Write information about this specific instance to the specified stream.booleanpropagateOnAbort()Determine if records are discarded on action abort or must be propagated to parents.booleanpropagateOnCommit()Determine if records are discarded on action commit or must be propagated to parents.voidreplace(AbstractRecord a)The current record is about to replace the one presented.booleanrestore_state(InputObjectState os, int i)During recovery, the transaction log is given to the recovery system and it will recreate a transaction instance to perform necessary recovery actions.booleansave_state(OutputObjectState os, int i)When the transaction is required to make the intentions list persistent, it scans the list and asks each record whether or not it requires state to be saved (by calling doSave).protected voidsetNext(AbstractRecord ar)Set the next element in the list to the specified instance.protected voidsetPrevious(AbstractRecord ar)Set the previous element in the list to the specified instance.abstract voidsetValue(Object o)abstract booleanshouldAdd(AbstractRecord a)Should we add the record presented to the intentions list?abstract booleanshouldAlter(AbstractRecord a)Should we alter the current record with the one presented?abstract booleanshouldMerge(AbstractRecord a)Should we merge the current record with the one presented?abstract booleanshouldReplace(AbstractRecord a)Should we replace the record presented with the current record?abstract inttopLevelAbort()A rollback of a top-level transaction has occurred.inttopLevelCleanup()Cleanup is called if a top-level action is detected to be an orphan.abstract inttopLevelCommit()A commit of a top-level transaction has occurred.inttopLevelOnePhaseCommit()Perform a top-level one phase commit.abstract inttopLevelPrepare()A prepare for a top-level transaction has occurred.Stringtype()Re-implementation of abstract methods inherited from base class.abstract inttypeIs()abstract Objectvalue()If this abstract record caused a heuristic then it should return an object which implementsHeuristicInformation-
Methods inherited from class com.arjuna.ats.arjuna.StateManager
activate, activate, cleanup, createLists, deactivate, deactivate, deactivate, destroy, disable, forgetAction, get_uid, getMutex, getObjectModel, getStore, getStoreRoot, loadObjectState, lockMutex, modified, objectType, packHeader, persist, rememberAction, setStatus, setupStore, setupStore, setupStore, status, terminate, tryLockMutex, unlockMutex, unpackHeader
-
-
-
-
Constructor Detail
-
AbstractRecord
protected AbstractRecord(Uid storeUid, String objType, int otype)
Create a new instance with the specified parameters.- Parameters:
storeUid- the unique id for this instance.objType- the type of the instance.otype- the ObjectType of the object.- See Also:
ObjectType
-
AbstractRecord
protected AbstractRecord(Uid storeUid)
Create a new instance with the specified paramaters.- Parameters:
storeUid- the unique id for this instance.
-
AbstractRecord
public AbstractRecord()
Creates a 'blank' abstract record. This is used during crash recovery when recreating the prepared list of a server atomic action.
-
-
Method Detail
-
typeIs
public abstract int typeIs()
- Returns:
RecordTypevalue.
-
value
public abstract Object value()
If this abstract record caused a heuristic then it should return an object which implementsHeuristicInformation- Returns:
Objectto be used to order.
-
setValue
public abstract void setValue(Object o)
-
nestedAbort
public abstract int nestedAbort()
A rollback of a nested transaction has occurred.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
nestedCommit
public abstract int nestedCommit()
A commit of a nested transaction has occurred.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
nestedPrepare
public abstract int nestedPrepare()
A prepare for a nested transaction has occurred.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
topLevelAbort
public abstract int topLevelAbort()
A rollback of a top-level transaction has occurred.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
topLevelCommit
public abstract int topLevelCommit()
A commit of a top-level transaction has occurred.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
topLevelPrepare
public abstract int topLevelPrepare()
A prepare for a top-level transaction has occurred.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
order
public Uid order()
Return the Uid of this abstract record so that it can be ordered in the intentions list. This is also the Uid that the record was saved with in the object store.- Returns:
Uidfor this instance.- See Also:
Uid
-
getTypeOfObject
public String getTypeOfObject()
Return the type of the abstract record. Used in ordering the instances in the intentions list. This is also the type that the record was saved with in the object store.- Returns:
Stringrepresenting type.
-
propagateOnAbort
public boolean propagateOnAbort()
Determine if records are discarded on action abort or must be propagated to parents.- Returns:
trueif the record should be propagated to the parent transaction if the current transaction rolls back,falseotherwise. The default isfalse.
-
propagateOnCommit
public boolean propagateOnCommit()
Determine if records are discarded on action commit or must be propagated to parents.- Returns:
trueif the record should be propagated to the parent transaction if the current transaction commits,falseotherwise. The default istrue.
-
equals
public final boolean equals(AbstractRecord ar)
Determine if two records are equal in that both are the same type and have the same order value (determined via 'order()').- Returns:
trueif equal,falseotherwise.
-
lessThan
public final boolean lessThan(AbstractRecord ar)
Determine if two records are less than in that both are the same type and their Uids are less than.- Returns:
trueif equal,falseotherwise.
-
greaterThan
public final boolean greaterThan(AbstractRecord ar)
Determine if two records are greater than in that both are the same type and their Uids are greater than.- Returns:
trueif equal,falseotherwise.
-
topLevelCleanup
public int topLevelCleanup()
Cleanup is called if a top-level action is detected to be an orphan. NOTE nested actions are never orphans since their parents would be aborted we may as well abort them as well.- Returns:
TwoPhaseOutcomeas default is the same as topLevelAbort.
-
nestedCleanup
public int nestedCleanup()
Cleanup is called if a nested is detected to be an orphan. NOTE nested actions are never orphans since their parents would be aborted we may as well abort them as well.- Returns:
TwoPhaseOutcomeas default is the same as nestedAbort.
-
doSave
public boolean doSave()
Should this record be saved in the intentions list? If the record is saved, then it may be recovered later in the event of a failure. Note, however, that the size of the intentions list on disk is critical to the performance of the system (disk I/O is a bottleneck).- Returns:
trueif it should be saved,falseotherwise.falseis the default.
-
type
public String type()
Re-implementation of abstract methods inherited from base class.- Overrides:
typein classStateManager
-
print
public void print(PrintWriter strm)
Write information about this specific instance to the specified stream.- Overrides:
printin classStateManager- Parameters:
strm- the stream on which to output.
-
save_state
public boolean save_state(OutputObjectState os, int i)
When the transaction is required to make the intentions list persistent, it scans the list and asks each record whether or not it requires state to be saved (by calling doSave). If the answer is yes, then save_state is called and the record instance must save enough information to enable it to be restored from that state later. The basic AbstractRecord save_state will save common data that is required by the base class during recovery. If a derived class calls super.save_state then it must be called before packing any other data item.- Overrides:
save_statein classStateManager- Returns:
trueif successful,falseotherwise.
-
restore_state
public boolean restore_state(InputObjectState os, int i)
During recovery, the transaction log is given to the recovery system and it will recreate a transaction instance to perform necessary recovery actions. This transaction will recreate the intentions list and give each recreated AbstractRecord the state that that was saved during transaction persistence. The base class will restore information that it needs from the log. Data items must be unpacked in the same order that they were packed.- Overrides:
restore_statein classStateManager- Returns:
trueif successful,falseotherwise.
-
forgetHeuristic
public boolean forgetHeuristic()
Forget any heuristic outcome which this implementation may have produced.- Returns:
trueby default. Iffalseis returned then the instance must be remembered by the transaction (in the log) in order for recovery to retry later or for a system administrator to be able to determine which resources have not been successfully completed.
-
clearHeuristicDecision
public void clearHeuristicDecision()
Clearing the heuristic state on the resource. If the resource maintains a state of the prior heuristic outcome then it should use this method to clear the state and forget the heuristic.
-
nestedOnePhaseCommit
public int nestedOnePhaseCommit()
Perform a nested one phase commit.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
isPermittedTopLevelOnePhaseCommit
public boolean isPermittedTopLevelOnePhaseCommit()
Defines if the participant record permits the use of the one phase commit optimization.
By default it's expected this to be true but the children records can override this if it's necessary for them to forbid 1PC to be run.
- Returns:
- true if 1PC could be run for the participant, otherwise false
-
topLevelOnePhaseCommit
public int topLevelOnePhaseCommit()
Perform a top-level one phase commit.- Returns:
TwoPhaseOutcometo indicate success/failure.- See Also:
TwoPhaseOutcome
-
create
public static AbstractRecord create(int type)
-
merge
public abstract void merge(AbstractRecord a)
Merge the current record with the one presented.- Parameters:
a- the record with which to merge.
-
alter
public abstract void alter(AbstractRecord a)
Alter the current record with the one presented.- Parameters:
a- the record with which to alter.
-
shouldAdd
public abstract boolean shouldAdd(AbstractRecord a)
Should we add the record presented to the intentions list?- Parameters:
a- The record to try to add.- Returns:
trueif the record should be added,falseotherwise.
-
shouldAlter
public abstract boolean shouldAlter(AbstractRecord a)
Should we alter the current record with the one presented?- Parameters:
a- The record to try to alter.- Returns:
trueif the record should be altered,falseotherwise.
-
shouldMerge
public abstract boolean shouldMerge(AbstractRecord a)
Should we merge the current record with the one presented?- Parameters:
a- The record to try to merge.- Returns:
trueif the record should be merged,falseotherwise.
-
shouldReplace
public abstract boolean shouldReplace(AbstractRecord a)
Should we replace the record presented with the current record?- Parameters:
a- The record to try to replace.- Returns:
trueif the record should be replaced,falseotherwise.
-
replace
public void replace(AbstractRecord a)
The current record is about to replace the one presented. This method is invoked to give the current record a chance to copy information, for example, from the record being replaced.- Parameters:
a- the record that will replace this instance.
-
getPrevious
protected final AbstractRecord getPrevious()
These few functions are link manipulation primitives used by the RecordList processing software to chain instances together.- Returns:
- the previous element in the intentions list, or null.
-
getNext
protected final AbstractRecord getNext()
- Returns:
- the next element in the intentions list, or null.
-
setPrevious
protected final void setPrevious(AbstractRecord ar)
Set the previous element in the list to the specified instance.- Parameters:
ar- the instance to become previous.
-
setNext
protected final void setNext(AbstractRecord ar)
Set the next element in the list to the specified instance.- Parameters:
ar- the instance to become next.
-
-