public class TransactionContext extends Object
Constructor and Description |
---|
TransactionContext(TransactionSystemClient txClient,
Iterable<TransactionAware> txAwares) |
TransactionContext(TransactionSystemClient txClient,
TransactionAware... txAwares) |
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts the given transaction, and rolls back all data set changes.
|
void |
abort(TransactionFailureException cause)
Aborts the given transaction, and rolls back all data set changes.
|
boolean |
addTransactionAware(TransactionAware txAware)
Adds a new transaction-aware to participate in the transaction.
|
void |
checkpoint()
Checkpoints the current transaction by flushing any pending writes for the registered
TransactionAware
instances, and obtaining a new current write pointer for the transaction. |
void |
finish()
Commits the current transaction.
|
Transaction |
getCurrentTransaction()
Returns the current transaction or null if no transaction is currently in progress.
|
boolean |
removeTransactionAware(TransactionAware txAware)
Removes a
TransactionAware and withdraws from participation in the transaction. |
void |
start()
Starts a new transaction.
|
void |
start(int timeout)
Starts a new transaction.
|
public TransactionContext(TransactionSystemClient txClient, TransactionAware... txAwares)
public TransactionContext(TransactionSystemClient txClient, Iterable<TransactionAware> txAwares)
public boolean addTransactionAware(TransactionAware txAware)
txAware
- the new transaction-awarepublic boolean removeTransactionAware(TransactionAware txAware)
TransactionAware
and withdraws from participation in the transaction.
Withdrawal is only allowed if there is no active transaction.txAware
- the TransactionAware
to be removedTransactionAware
is removed; false otherwise.IllegalStateException
- if there is an active transaction going on with this TransactionContext.public void start() throws TransactionFailureException
TransactionSystemClient
,
and pass the returned transaction to TransactionAware.startTx(Transaction)
for each registered
TransactionAware. If an exception is encountered, the transaction will be aborted and a
TransactionFailureException
wrapping the root cause will be thrown.TransactionFailureException
- if an exception occurs starting the transaction with any registered
TransactionAwarepublic void start(int timeout) throws TransactionFailureException
TransactionSystemClient
,
and pass the returned transaction to TransactionAware.startTx(Transaction)
for each registered
TransactionAware. If an exception is encountered, the transaction will be aborted and a
TransactionFailureException
wrapping the root cause will be thrown.timeout
- the transaction timeout for the transactionTransactionFailureException
- if an exception occurs starting the transaction with any registered
TransactionAwarepublic void finish() throws TransactionFailureException
TransactionAware
instances; flush any pending writes from the TransactionAware
s;
commit the current transaction with the TransactionSystemClient
; and clear the current transaction state.TransactionConflictException
- if a conflict is detected with a recently committed transactionTransactionFailureException
- if an error occurs while committingpublic void abort() throws TransactionFailureException
TransactionFailureException
- for any exception that is encountered.public void checkpoint() throws TransactionFailureException
TransactionAware
instances, and obtaining a new current write pointer for the transaction. By performing a checkpoint,
the client can ensure that all previous writes were flushed and are visible. By default, the current write
pointer for the transaction is also visible. The current write pointer can be excluded from read
operations by calling Transaction.setVisibility(Transaction.VisibilityLevel)
with the visibility level set
to Transaction.VisibilityLevel.SNAPSHOT_EXCLUDE_CURRENT
on the Transaction
instance created
by the checkpoint call, which can be retrieved by calling getCurrentTransaction()
.
After the checkpoint operation is performed, the updated
Transaction
instance will be passed to TransactionAware.startTx(Transaction)
for each
registered TransactionAware
instance.TransactionFailureException
- if an error occurs while performing the checkpoint@Nullable public Transaction getCurrentTransaction()
public void abort(TransactionFailureException cause) throws TransactionFailureException
cause
- the original exception that caused the abortTransactionFailureException
- for any exception that is encountered.Copyright © 2016 The Apache Software Foundation. All rights reserved.