Interface TransactionContext
- All Known Subinterfaces:
Transaction
A subset of a
Transaction
that lets participants properly take part in transactions, manage their state,
or open nested transactions, but does not allow them to close the transaction they are passed.
Experimental feature, we reserve the right to remove or change it without further notice. The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A callback that is invoked when a transaction is closed.static interface
A callback that is invoked after the outer transaction is closed.static enum
The result of a transaction operation. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCloseCallback
(TransactionContext.CloseCallback closeCallback) Register a callback that will be invoked when this transaction is closed.void
addOuterCloseCallback
(TransactionContext.OuterCloseCallback outerCloseCallback) Register a callback that will be invoked after the outermost transaction is closed, and after callbacks registered withaddCloseCallback(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.CloseCallback)
are ran.getOpenTransaction
(int nestingDepth) Return the transaction with the specific nesting depth.int
Open a new nested transaction.
-
Method Details
-
openNested
Transaction openNested()Open a new nested transaction.- Throws:
IllegalStateException
- If this function is not called on the thread this transaction was opened in.IllegalStateException
- If this transaction is not the current transaction.IllegalStateException
- If this transaction was closed.
-
nestingDepth
int nestingDepth()- Returns:
- The nesting depth of this transaction: 0 if it was opened with
Transaction.openOuter()
, 1 if its parent was opened withTransaction.openOuter()
, and so on... - Throws:
IllegalStateException
- If this function is not called on the thread this transaction was opened in.
-
getOpenTransaction
Return the transaction with the specific nesting depth.- Parameters:
nestingDepth
- Queried nesting depth.- Throws:
IndexOutOfBoundsException
- If there is no open transaction with the request nesting depth.IllegalStateException
- If this function is not called on the thread this transaction was opened in.
-
addCloseCallback
Register a callback that will be invoked when this transaction is closed. Registered callbacks are invoked last-to-first: the last callback to be registered will be the first to be invoked, and so on...Updates that may change the state of other participants should be deferred until after the outermost transaction is closed using
addOuterCloseCallback(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.OuterCloseCallback)
.- Throws:
IllegalStateException
- If this function is not called on the thread this transaction was opened in.
-
addOuterCloseCallback
Register a callback that will be invoked after the outermost transaction is closed, and after callbacks registered withaddCloseCallback(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.CloseCallback)
are ran. Registered callbacks are invoked last-to-first.- Throws:
IllegalStateException
- If this function is not called on the thread this transaction was opened in.
-