public interface TransactionAware
TransactionAware dataSet = // ... // dataSet is one example of component that interacts with tx logic Transaction tx = txClient.start(); dataSet.startTx(tx); // notifying about new transaction dataSet.write(...); // ... do other operations on dataSet Collectionchanges = dataSet.getTxChanges(); boolean rollback = true; if (txClient.canCommit(changes)) { // checking conflicts before commit, if none, commit tx if (dataSet.commitTx()) { // try persisting changes if (txClient.commit(tx)) { // if OK, make tx visible; if not - tx stays invisible to others dataSet.postTxCommit(); // notifying dataset about tx commit success via callback rollback = false; } } } if (rollback) { // if there are conflicts (or cannot commit), try rollback changes if (dataSet.rollbackTx()) { // try undo changes txClient.abort(tx); // if OK, make tx visible; if not - tx stays invisible to others } }
Modifier and Type | Method and Description |
---|---|
boolean |
commitTx()
Called before transaction has been committed.
|
String |
getTransactionAwareName()
Used for error reporting.
|
Collection<byte[]> |
getTxChanges() |
void |
postTxCommit()
Called after transaction has been committed.
|
boolean |
rollbackTx()
Called during transaction rollback (for whatever reason: conflicts, errors, etc.).
|
void |
startTx(Transaction tx)
Called when new transaction has started.
|
void |
updateTx(Transaction tx)
Called when the state of the current transaction has been updated.
|
void startTx(Transaction tx)
tx
- transaction infovoid updateTx(Transaction tx)
Transaction
held by this TransactionAware
, but should not reset
any state (such as the write change sets) that is currently maintained.tx
- the updated transactionCollection<byte[]> getTxChanges()
boolean commitTx() throws Exception
Exception
void postTxCommit()
RuntimeException
- in case of serious failure that should not be ignored.boolean rollbackTx() throws Exception
Exception
String getTransactionAwareName()
Copyright © 2016 The Apache Software Foundation. All rights reserved.