|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Transaction
All changes on transaction objects must be done through a Transaction. The transaction make sure that changes on java objects are:
registerLifecycleListener(TransactionLifecycleListener).
When the Transaction is reset, the lifecycle tasks are dropped. So the lifecycle task need to be registered again.
Condition functionality already provided. For more information see the
registerRetryLatch(Latch).
Because a custom Latch implementation can be provided, you have a lot of control on the blocking behavior.
But atm it is not possible to get fairness on when the Latch is opened. Policies to customize starvation,
lifelocking, deadlocking will be added in the future.
| Method Summary | |
|---|---|
void |
abort()
Aborts this Transaction. |
void |
commit()
Commits this Transaction. |
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. |
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. |
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 timeoutNs)
Sets the remaining timeout in nanoseconds. |
void |
start()
Starts the Transaction. |
| Method Detail |
|---|
TransactionFactory getTransactionFactory()
Stm getStm()
TransactionConfiguration getConfiguration()
TransactionConfiguration that is used by this Transaction.
long getReadVersion()
TransactionStatus getStatus()
int getAttempt()
void setAttempt(int attempt)
attempt - the current attempt
IllegalArgumentException - if attempt smaller than zero.long getRemainingTimeoutNs()
void setRemainingTimeoutNs(long timeoutNs)
timeoutNs - the timeout.
IllegalArgumentException - if timeout smaller than 0.void start()
IllegalTransactionStateException - if the Transaction is not in the correct state for this operation.void commit()
WriteConflict - if the commit failed. Check the class hierarchy of the WriteConflict for more information.
DeadTransactionException - if this transaction already is aborted.void prepare()
WriteConflict - if the transaction can't be prepared.
DeadTransactionException - if the transaction already is committed or aborted.void abort()
DeadTransactionException - if this transaction already is committedvoid reset()
ControlFlowError 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.
void registerRetryLatch(Latch latch)
Future because it also pops closed once some event occurs (an interesting write
in the case of a Latch).
latch - the Latch to register.
NullPointerException - if latch is null.
NoRetryPossibleException - if the retry can't make progress, e.g. because the transaction has not
loaded any object.
DeadTransactionException - if this transaction already is committed or aborted.
UnsupportedOperationException - if the Transaction doesn't support this operation (for example because it
doesn't do readtracking).void registerLifecycleListener(TransactionLifecycleListener listener)
TransactionStatus 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.
listener - the TransactionLifecycleListener to registerLifecycleListener
NullPointerException - if listener is null.
DeadTransactionException - if transaction already is aborted or committed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||