Class UnmanagedTransaction
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 Summary
ConstructorsConstructorDescriptionUnmanagedTransaction(String transactionId, TransactionManager transactionManager, String traversalSourceName, Graph graph, ScheduledExecutorService scheduledExecutorService, long idleTransactionTimeout, long perGraphClose) Creates a newUnmanagedTransactionfor managing an HTTP transaction. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose(boolean force) Closes this transaction and releases its resources.Returns the transaction ID.Returns the traversal source name bound at begin time.Future<?>submit(FutureTask<Void> task, Context context) Submits a task to be executed within this transaction's thread context.
-
Constructor Details
-
UnmanagedTransaction
public UnmanagedTransaction(String transactionId, TransactionManager transactionManager, String traversalSourceName, Graph graph, ScheduledExecutorService scheduledExecutorService, long idleTransactionTimeout, long perGraphClose) Creates a newUnmanagedTransactionfor managing an HTTP transaction.- Parameters:
transactionId- The unique identifier for this transactiontransactionManager- The manager that owns this transaction's lifecycletraversalSourceName- The traversal source name bound at begin timegraph- The graph instance for this transactionscheduledExecutorService- Scheduler for timeout managementidleTransactionTimeout- Inactivity timeout in milliseconds before auto-rollback;0disables it
-
-
Method Details
-
getTransactionId
Returns the transaction ID. -
getTraversalSourceName
Returns the traversal source name bound at begin time. -
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
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 threadcontext- The request context driving this task, recorded so the lifetime cap can flag it before interrupting; may benullfor 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
-