Class LoomTransaction

java.lang.Object
com.loomcache.client.LoomTransaction
All Implemented Interfaces:
AutoCloseable

public final class LoomTransaction extends Object implements 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 Details

    • put

      public void put(String mapName, String key, String value)
    • delete

      public void delete(String mapName, String key)
    • putIfAbsent

      public void putIfAbsent(String mapName, String key, String value)
    • setAdd

      public void setAdd(String setName, String member)
    • setRemove

      public void setRemove(String setName, String member)
    • queueOffer

      public void queueOffer(String queueName, String element)
    • queuePoll

      public void queuePoll(String queueName)
    • multiMapPut

      public void multiMapPut(String name, String key, String value)
    • multiMapRemove

      public void multiMapRemove(String name, String key, String value)
    • getForUpdate

      public @Nullable String getForUpdate(String mapName, String key)
      Pessimistically locks a map key for this transaction and returns its current value.
    • 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 by close() if neither commit nor rollback has been called.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable