Class SnapshotParticipant<T>
- Type Parameters:
T
- The objects that this participant uses to save its state snapshots. 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.
- All Implemented Interfaces:
TransactionContext.CloseCallback
,TransactionContext.OuterCloseCallback
- Direct Known Subclasses:
SingleFluidStorage
,SingleStackStorage
,SingleVariantStorage
T
in case it needs to revert to a previous state.
updateSnapshots(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
should be called before any modification.
This will save the state of this participant using createSnapshot()
if no state was already saved for that transaction.
When the transaction is aborted and changes need to be rolled back, readSnapshot(T)
will be called
to signal that the current state should revert to that of the snapshot.
The snapshot object is then released, and can be cached for subsequent use, or discarded.
When an outer transaction is committed, readSnapshot(T)
will not be called so that the current state of this participant
is retained. releaseSnapshot(T)
will be called because the snapshot is not necessary anymore,
and onFinalCommit()
will be called after the transaction is closed.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Perform an action after the top-level transaction is closed.protected abstract T
Return a new nonnull object containing the current state of this participant.void
onClose
(TransactionContext transaction, TransactionContext.Result result) Perform an action when a transaction is closed.protected void
Called after an outer transaction succeeded, to perform irreversible actions such asmarkDirty()
or neighbor updates.protected abstract void
readSnapshot
(T snapshot) Roll back to a state previously created bycreateSnapshot()
.protected void
releaseSnapshot
(T snapshot) Signals that the snapshot will not be used anymore, and is safe to cache for next calls tocreateSnapshot()
, or discard entirely.void
updateSnapshots
(TransactionContext transaction) Update the stored snapshots so that the changes happening as part of the passed transaction can be correctly committed or rolled back.
-
Constructor Details
-
SnapshotParticipant
public SnapshotParticipant()
-
-
Method Details
-
createSnapshot
Return a new nonnull object containing the current state of this participant.null
may not be returned, or an exception will be thrown! -
readSnapshot
Roll back to a state previously created bycreateSnapshot()
. -
releaseSnapshot
Signals that the snapshot will not be used anymore, and is safe to cache for next calls tocreateSnapshot()
, or discard entirely. -
onFinalCommit
protected void onFinalCommit()Called after an outer transaction succeeded, to perform irreversible actions such asmarkDirty()
or neighbor updates. -
updateSnapshots
Update the stored snapshots so that the changes happening as part of the passed transaction can be correctly committed or rolled back. This function should be called every time the participant is about to change its internal state as part of a transaction. -
onClose
Description copied from interface:TransactionContext.CloseCallback
Perform an action when a transaction is closed.- Specified by:
onClose
in interfaceTransactionContext.CloseCallback
- Parameters:
transaction
- The closed transaction. OnlyTransactionContext.nestingDepth()
,TransactionContext.getOpenTransaction(int)
andTransactionContext.addOuterCloseCallback(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.OuterCloseCallback)
may be called on that transaction.TransactionContext.addCloseCallback(net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext.CloseCallback)
may additionally be called on parent transactions (accessed throughTransactionContext.getOpenTransaction(int)
for lower nesting depths).result
- The result of this transaction: whether it was committed or aborted.
-
afterOuterClose
Description copied from interface:TransactionContext.OuterCloseCallback
Perform an action after the top-level transaction is closed.- Specified by:
afterOuterClose
in interfaceTransactionContext.OuterCloseCallback
- Parameters:
result
- The result of the top-level transaction.
-