Class LoomTransaction
java.lang.Object
com.loomcache.client.LoomTransaction
- All Implemented Interfaces:
AutoCloseable
Client-side facade for a transaction.
Usage
try (LoomTransaction tx = client.newTransaction()) {
tx.put("users", "user:1", "Alice");
tx.delete("users", "user:2");
tx.commit();
}
By default the client buffers transaction operations locally and submits
them as a single TX_COMMIT request. This avoids pinning the
transaction to one node before commit, so a leader change during the
buffering phase does not destroy the transaction.
The legacy stateful pinned-connection mode remains available internally for compatibility with older protocol flows.
Auto-rollback: close() rolls back the transaction if neither
commit() nor rollback() has been called.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidcommit()Commit the transaction.void@Nullable StringgetForUpdate(String mapName, String key) Pessimistically locks a map key for this transaction and returns its current value.voidmultiMapPut(String name, String key, String value) voidmultiMapRemove(String name, String key, String value) voidvoidputIfAbsent(String mapName, String key, String value) voidqueueOffer(String queueName, String element) voidvoidrollback()Explicitly roll back the transaction.voidvoid
-
Method Details
-
put
-
delete
-
putIfAbsent
-
setAdd
-
setRemove
-
queueOffer
-
queuePoll
-
multiMapPut
-
multiMapRemove
-
getForUpdate
-
commit
public void commit()Commit the transaction. All buffered operations execute atomically on the server; a failure causes every already-executed op to roll back before this method throws. -
rollback
public void rollback()Explicitly roll back the transaction. Safe to call multiple times - subsequent calls are no-ops. Also invoked automatically byclose()if neither commit nor rollback has been called. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-