Class UnmanagedTransaction

java.lang.Object
org.apache.tinkerpop.gremlin.server.transaction.UnmanagedTransaction

public class UnmanagedTransaction extends Object
Maintains state for an active transaction over HTTP.

Key design principle: Graph transactions are ThreadLocal-bound, so all operations for a transaction must execute on the same thread. This is achieved via a single-threaded executor. Callers submit FutureTask instances that contain the complete request lifecycle (graph operation, error handling, response writing), following the same pattern as the non-transactional HTTP path and the legacy SessionOpProcessor.

The single-threaded executor is a UnmanagedTransaction.SingleThreadTransactionExecutor (a ThreadPoolExecutor with one core/max thread) rather than Executors.newSingleThreadExecutor(). It is behaviorally identical for task execution but exposes the beforeExecute/afterExecute lifecycle hooks and the task queue, which the idle-timer management relies on to tell "an operation is running" apart from "the worker is idle with an empty queue". The Executors factory hides those behind a sealed wrapper.

  • Constructor Details

    • UnmanagedTransaction

      public UnmanagedTransaction(String transactionId, TransactionManager transactionManager, String traversalSourceName, Graph graph, ScheduledExecutorService scheduledExecutorService, long idleTransactionTimeout, long perGraphClose)
      Creates a new UnmanagedTransaction for managing an HTTP transaction.
      Parameters:
      transactionId - The unique identifier for this transaction
      transactionManager - The manager that owns this transaction's lifecycle
      traversalSourceName - The traversal source name bound at begin time
      graph - The graph instance for this transaction
      scheduledExecutorService - Scheduler for timeout management
      idleTransactionTimeout - Inactivity timeout in milliseconds before auto-rollback; 0 disables it
  • Method Details

    • getTransactionId

      public String getTransactionId()
      Returns the transaction ID.
    • getTraversalSourceName

      public String getTraversalSourceName()
      Returns the traversal source name bound at begin time.
    • close

      public void close(boolean force)
      Closes this transaction and releases its resources. When force is false, any open graph transaction is rolled back before shutdown. When force is true, the executor is shut down immediately without attempting a rollback.
      Parameters:
      force - if true, skip the rollback attempt and shut down immediately
    • submit

      public Future<?> submit(FutureTask<Void> task, Context context)
      Submits a task to be executed within this transaction's thread context. The task should contain the complete request lifecycle: graph operation, error handling, and response writing.
      Parameters:
      task - The FutureTask to execute on the transaction thread
      context - The request context driving this task, recorded so the lifetime cap can flag it before interrupting; may be null for internal operations (such as the begin's tx open) where no user-facing error needs to be tailored
      Returns:
      Future that can be used for timeout cancellation
      Throws:
      IllegalStateException - if the transaction is closed