|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.multiverse.stms.AbstractTransaction<C,S>
public abstract class AbstractTransaction<C extends AbstractTransactionConfiguration,S extends AbstractTransactionSnapshot>
An abstract Transaction implementation that contains most of the plumbing logic. Extend
this and prevent duplicate logic.
init() when it has completed its constructor. Can't be done inside the
constructor of the AbstractTransaction because fields in the subclass perhaps are not set.
AbstractTransaction requires the clock.time to be at least 1. It used the version field to encode the transaction
state. See the version field for more information.
| Field Summary | |
|---|---|
protected C |
config
|
| Fields inherited from interface org.multiverse.MultiverseConstants |
|---|
___SANITY_CHECKS_ENABLED |
| Constructor Summary | |
|---|---|
AbstractTransaction(C config)
|
|
| Method Summary | |
|---|---|
void |
abort()
Aborts this Transaction. |
void |
commit()
Commits this Transaction. |
protected void |
doAbortActive()
Method is designed to be overridden to add custom behavior on the abort of the transaction. |
protected void |
doAbortPrepared()
|
protected void |
doClear()
|
protected void |
doInit()
Method is designed to be overridden to add custom behavior on the init of the transaction. |
protected void |
doPrepare()
|
protected boolean |
doRegisterRetryLatch(Latch latch,
long wakeupVersion)
Register retry. |
void |
endOr()
|
void |
endOrAndStartElse()
|
int |
getAttempt()
|
TransactionConfiguration |
getConfiguration()
Gets the TransactionConfiguration that is used by this Transaction. |
long |
getReadVersion()
Returns the clock version of the stm when this Transaction started. |
long |
getRemainingTimeoutNs()
|
protected S |
getSnapshot()
|
TransactionStatus |
getStatus()
Returns the status of this Transaction. |
protected void |
init()
|
protected void |
makeChangesPermanent()
|
void |
prepare()
Prepares this transaction to be committed. |
void |
registerLifecycleListener(TransactionLifecycleListener listener)
Registers a TransactionLifecycleListener on this Transaction. |
void |
registerRetryLatch(Latch latch)
Registers the retry Latch on this Transaction. |
void |
restart()
Restarts this Transaction. |
void |
setAttempt(int attempt)
|
void |
setRemainingTimeoutNs(long newTimeoutNs)
|
void |
startOr()
|
protected void |
storeSnapshot(S snapshot)
|
protected S |
takeSnapshot()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final C extends AbstractTransactionConfiguration config
| Constructor Detail |
|---|
public AbstractTransaction(C config)
| Method Detail |
|---|
public final int getAttempt()
getAttempt in interface Transactionpublic final void setAttempt(int attempt)
setAttempt in interface Transactionpublic final long getRemainingTimeoutNs()
getRemainingTimeoutNs in interface Transactionpublic final void setRemainingTimeoutNs(long newTimeoutNs)
setRemainingTimeoutNs in interface Transactionpublic final long getReadVersion()
Transaction
getReadVersion in interface Transactionpublic final TransactionStatus getStatus()
Transaction
getStatus in interface Transactionpublic TransactionConfiguration getConfiguration()
TransactionTransactionConfiguration that is used by this Transaction.
getConfiguration in interface Transactionprotected final void init()
protected void doInit()
protected void doClear()
public final void registerLifecycleListener(TransactionLifecycleListener listener)
TransactionTransactionStatus of that transaction. Without this functionality it would not
be possible to execute compensating or deferred action once a transaction aborts or commits.
If the execution of one of the listeners fails, the others won't be executed. If one of the listeners fails
before the commit/abort, the transaction is aborted (no matter what).
The listeners are executed in the order they are registered.
If the same listener is added multiple times, it will be notified multiple times.
The listener will be executed on the thread that starts the commit/abort.
If the listener is added after the Transaction is prepared, the preCommit event will not be called on the
listener.
If the listener accesses the stm after the transaction has been committed or aborted, it could see changes
made after that transaction. So all assumptions about state are possibly wrong so one needs to take care of
re-validating state if needed.
A good use case of this feature is starting up threads. If you need to start threads, you don't want to start
them immediately because eventually the transaction could be aborted.
registerLifecycleListener in interface Transactionlistener - the TransactionLifecycleListener to registerLifecycleListenerpublic final void prepare()
Transaction
prepare in interface Transactionprotected void doPrepare()
public final void restart()
Transaction
restart in interface Transactionpublic final void abort()
Transaction
abort in interface Transactionprotected void doAbortPrepared()
protected void doAbortActive()
public final void commit()
Transaction
commit in interface Transactionprotected void makeChangesPermanent()
public final void registerRetryLatch(Latch latch)
TransactionFuture because it also pops closed once some event occurs (an interesting write
in the case of a Latch).
registerRetryLatch in interface Transactionlatch - the Latch to register.
protected boolean doRegisterRetryLatch(Latch latch,
long wakeupVersion)
latch - the latch to registerLifecycleListener. Value will never be null.wakeupVersion - the minimal version of the transactional object to wakeup for.
public final void startOr()
public final void endOr()
public final void endOrAndStartElse()
protected S takeSnapshot()
protected S getSnapshot()
protected void storeSnapshot(S snapshot)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||