|
||||||||||
| 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.
| Field Summary | |
|---|---|
static int |
ABORTED
|
static int |
ACTIVE
|
static int |
COMMITTED
|
protected C |
config
|
static int |
NEW
|
static int |
PREPARED
|
protected int |
statusInt
|
protected long |
timeoutNs
|
protected long |
version
|
| Fields inherited from interface org.multiverse.MultiverseConstants |
|---|
___BUGSHAKER_ENABLED, ___TRACING_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 |
doPrepare()
|
protected boolean |
doRegisterRetryLatch(Latch latch,
long wakeupVersion)
Register retry. |
protected void |
doReset()
|
protected void |
doStart()
Method is designed to be overridden to add custom behavior on the init of the transaction. |
void |
endOr()
|
void |
endOrAndStartElse()
|
int |
getAttempt()
Gets the current attempt (so the number of tries this transaction already had). |
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()
Gets the remaining timeout in nanoseconds. |
protected S |
getSnapshot()
|
TransactionStatus |
getStatus()
Returns the status of this Transaction. |
Stm |
getStm()
Returns the Stm that started this Transaction. |
TransactionFactory |
getTransactionFactory()
Returns the TransactionFactory that started this Transaction. |
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 |
reset()
Resets this Transaction so it can be reused. |
void |
setAttempt(int attempt)
Sets the current attempt. |
void |
setRemainingTimeoutNs(long newTimeoutNs)
Sets the remaining timeout in nanoseconds. |
void |
start()
Starts the Transaction. |
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
protected long version
public static final int NEW
public static final int ACTIVE
public static final int PREPARED
public static final int COMMITTED
public static final int ABORTED
protected int statusInt
protected long timeoutNs
| Constructor Detail |
|---|
public AbstractTransaction(C config)
| Method Detail |
|---|
public final int getAttempt()
Transaction
getAttempt in interface Transactionpublic final void setAttempt(int attempt)
Transaction
setAttempt in interface Transactionattempt - the current attemptpublic final long getRemainingTimeoutNs()
Transaction
getRemainingTimeoutNs in interface Transactionpublic final void setRemainingTimeoutNs(long newTimeoutNs)
Transaction
setRemainingTimeoutNs in interface TransactionnewTimeoutNs - the timeout.public final long getReadVersion()
Transaction
getReadVersion in interface Transactionpublic final TransactionStatus getStatus()
Transaction
getStatus in interface Transactionpublic final TransactionConfiguration getConfiguration()
TransactionTransactionConfiguration that is used by this Transaction.
getConfiguration in interface Transactionpublic final Stm getStm()
Transaction
getStm in interface Transactionpublic final TransactionFactory getTransactionFactory()
Transaction
getTransactionFactory in interface Transactionprotected void doStart()
protected void doReset()
public void start()
Transaction
start in interface Transactionpublic 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.
The registration is 'transactional', so when the transaction is restarted, the listeners need
to be registered again. In most cases this is the behavior wanted because listeners are added
inside the atomic 'block' and this block is re-executed when a failure occurs.
registerLifecycleListener in interface Transactionlistener - the TransactionLifecycleListener to registerLifecycleListenerpublic final void prepare()
Transaction
prepare in interface Transactionprotected void doPrepare()
public final void reset()
TransactionControlFlowError or when
an old transaction on the ThreadLocalTransaction is found that can be reused.
If the Transaction is prepared or committed, it will be aborted before it is reset. If there are
TransactionLifecycleListeners that cause problems while executing the pre/post abort notification, the
transaction will be aborted and the exception will be propagated.
reset 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 | |||||||||