Class UnmanagedTransaction
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.server.handler.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
FutureTaskinstances that contain the complete request lifecycle (graph operation, error handling, response writing), following the same pattern as the non-transactional HTTP path and the legacySessionOpProcessor.
-
-
Constructor Summary
Constructors Constructor Description UnmanagedTransaction(String transactionId, TransactionManager transactionManager, Graph graph, ScheduledExecutorService scheduledExecutorService, long transactionTimeout, long perGraphClose)Creates a newUnmanagedTransactionfor managing an HTTP transaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose(boolean force)Closes this transaction and releases its resources.StringgetTransactionId()Returns the transaction ID.voidopen()Opens the underlying graph transaction and starts the inactivity timeout.Future<?>submit(FutureTask<Void> task)Submits a task to be executed within this transaction's thread context.voidtouch()Resets the timeout for this transaction.
-
-
-
Constructor Detail
-
UnmanagedTransaction
public UnmanagedTransaction(String transactionId, TransactionManager transactionManager, Graph graph, ScheduledExecutorService scheduledExecutorService, long transactionTimeout, long perGraphClose)
Creates a newUnmanagedTransactionfor managing an HTTP transaction.- Parameters:
transactionId- The unique identifier for this transactiontransactionManager- The manager that owns this transaction's lifecyclegraph- The graph instance for this transactionscheduledExecutorService- Scheduler for timeout managementtransactionTimeout- Timeout in milliseconds before auto-rollback
-
-
Method Detail
-
getTransactionId
public String getTransactionId()
Returns the transaction ID.
-
touch
public void touch()
Resets the timeout for this transaction. Called on each request.
-
open
public void open()
Opens the underlying graph transaction and starts the inactivity timeout. Should be called on the transaction's single-threaded executor to preserve ThreadLocal affinity. On failure the exception is re-thrown and the caller is responsible for cleanup (e.g. viaclose(boolean)).
-
close
public void close(boolean force)
Closes this transaction and releases its resources. Whenforceisfalse, any open graph transaction is rolled back before shutdown. Whenforceistrue, the executor is shut down immediately without attempting a rollback.- Parameters:
force- iftrue, skip the rollback attempt and shut down immediately
-
submit
public Future<?> submit(FutureTask<Void> task)
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- Returns:
- Future that can be used for timeout cancellation
- Throws:
IllegalStateException- if the transaction is closed
-
-