public class Transaction<T> extends Object
The Transaction object is used to manage the transaction for a single partition primitive that implements
the Transactional interface. It's used as a proxy for TransactionContexts to manage the transaction
as it relates to a single piece of atomic state.
| Modifier and Type | Field and Description |
|---|---|
protected Transactional<T> |
transactionalObject |
protected TransactionId |
transactionId |
| Constructor and Description |
|---|
Transaction(TransactionId transactionId,
Transactional<T> transactionalObject) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Version> |
begin()
Begins the transaction.
|
protected void |
checkActive()
Checks that the transaction state is
ACTIVE and throws an IllegalStateException if not. |
protected void |
checkOpen()
Checks that the transaction is open and throws an
IllegalStateException if not. |
protected void |
checkPrepared()
Checks that the transaction state is
PREPARED and throws an IllegalStateException if not. |
CompletableFuture<Void> |
commit()
Commits the transaction.
|
boolean |
isOpen()
Returns a boolean indicating whether the transaction is open.
|
protected void |
open()
Opens the transaction, throwing an
IllegalStateException if it's already open. |
CompletableFuture<Boolean> |
prepare(List<T> updates)
Prepares the transaction.
|
CompletableFuture<Boolean> |
prepareAndCommit(List<T> updates)
Prepares and commits the transaction in a single atomic operation.
|
CompletableFuture<Void> |
rollback()
Rolls back the transaction.
|
protected void |
setState(org.onosproject.store.primitives.impl.Transaction.State state)
Updates the transaction state.
|
org.onosproject.store.primitives.impl.Transaction.State |
state()
Returns the current transaction state.
|
String |
toString() |
TransactionId |
transactionId()
Returns the transaction identifier.
|
protected final TransactionId transactionId
protected final Transactional<T> transactionalObject
public Transaction(TransactionId transactionId, Transactional<T> transactionalObject)
public TransactionId transactionId()
public org.onosproject.store.primitives.impl.Transaction.State state()
public boolean isOpen()
protected void open()
IllegalStateException if it's already open.protected void checkOpen()
IllegalStateException if not.protected void checkActive()
ACTIVE and throws an IllegalStateException if not.protected void checkPrepared()
PREPARED and throws an IllegalStateException if not.protected void setState(org.onosproject.store.primitives.impl.Transaction.State state)
state - the updated transaction statepublic CompletableFuture<Version> begin()
Locks are acquired when the transaction is begun to prevent concurrent transactions from operating on the shared resource to which this transaction relates.
public CompletableFuture<Boolean> prepare(List<T> updates)
When preparing the transaction, the given list of updates for the shared resource will be prepared, and
concurrent modification checks will be performed. The returned future may be completed with a
TransactionException if a concurrent modification is detected for an isolation level that does
not allow such modifications.
updates - the transaction updatespublic CompletableFuture<Boolean> prepareAndCommit(List<T> updates)
Both the prepare and commit phases of the protocol must be executed within a single atomic operation. This method is used to optimize committing transactions that operate only on a single partition within a single primitive.
updates - the transaction updatespublic CompletableFuture<Void> commit()
Performs the second phase of the two-phase commit protocol, committing the previously
prepared updates.
public CompletableFuture<Void> rollback()
Rolls back the first phase of the two-phase commit protocol, cancelling prepared updates.