Class HttpRemoteTransaction

  • All Implemented Interfaces:
    AutoCloseable, RemoteTransaction, RequestSubmitter, Transaction

    public class HttpRemoteTransaction
    extends Object
    implements RemoteTransaction
    A Transaction implementation for HTTP-based remote connections.

    This class provides synchronous, sequential request execution within a transaction context. All requests are pinned to a single host and include the transaction ID (after begin()).

    Key characteristics:

    • Synchronous API only - no submitAsync() methods
    • Host pinning - all requests go to the same server
    • Sequential execution - requests block until complete

    Usage:

     Transaction tx = cluster.transact("g");
     GraphTraversalSource gtx = tx.begin();
     gtx.addV("person").property("name", "alice").iterate();
     tx.commit();
     
    This class is NOT thread-safe.
    • Constructor Detail

      • HttpRemoteTransaction

        public HttpRemoteTransaction​(Client.PinnedClient pinnedClient,
                                     String graphAlias)
        Creates a new HTTP transaction.

        The transaction is not started until begin(Class) is called. A host is selected at creation time and all requests will be pinned to it.

        Parameters:
        pinnedClient - the underlying client for connection access
        graphAlias - the graph/traversal source alias (e.g., "g")
        Throws:
        NoHostAvailableException - if no hosts are available in the cluster
    • Method Detail

      • begin

        public <T extends TraversalSource> T begin​(Class<T> traversalSourceClass)
        Starts a transaction and returns a traversal source bound to it.

        This method sends g.tx().begin() to the server, which returns the transaction ID. All subsequent requests will include this ID.

        Specified by:
        begin in interface Transaction
        Type Parameters:
        T - the type of the traversal source
        Parameters:
        traversalSourceClass - the class of the traversal source to create
        Returns:
        a new traversal source bound to this transaction
        Throws:
        IllegalStateException - if the transaction is already started
        RuntimeException - if the transaction fails to begin
      • getTransactionId

        public String getTransactionId()
        Returns the server-generated transaction ID, or null if the transaction has not yet been started via begin(Class).
        Specified by:
        getTransactionId in interface RemoteTransaction
        Returns:
        the transaction ID, or null if not yet begun
      • isOpen

        public boolean isOpen()
        Description copied from interface: Transaction
        Determines if a transaction is currently open.
        Specified by:
        isOpen in interface Transaction
      • readWrite

        public void readWrite()
        Description copied from interface: Transaction
        An internal function that signals a read or a write has occurred - not meant to be called directly by end users.
        Specified by:
        readWrite in interface Transaction
      • addTransactionListener

        public void addTransactionListener​(Consumer<Transaction.Status> listener)
        Description copied from interface: Transaction
        Adds a listener that is called back with a status when a commit or rollback is successful. It is expected that listeners be bound to the current thread as is standard for transactions. Therefore a listener registered in the current thread will not get callback events from a commit or rollback call in a different thread.
        Specified by:
        addTransactionListener in interface Transaction
      • submit

        public ResultSet submit​(String gremlin)
        Description copied from interface: RequestSubmitter
        Submits a Gremlin script and blocks until the response is received.
        Specified by:
        submit in interface RequestSubmitter
        Parameters:
        gremlin - the Gremlin script to execute
        Returns:
        the results of the script execution
      • submit

        public ResultSet submit​(String gremlin,
                                Map<String,​Object> parameters)
        Description copied from interface: RequestSubmitter
        Submits a Gremlin script with bound parameters and blocks until the response is received.

        Prefer this method over string concatenation when executing scripts with variable arguments, as parameterized scripts perform better.

        Specified by:
        submit in interface RequestSubmitter
        Parameters:
        gremlin - the Gremlin script to execute
        parameters - a map of parameters that will be bound to the script on execution
        Returns:
        the results of the script execution
      • submit

        public ResultSet submit​(String gremlin,
                                RequestOptions options)
        Description copied from interface: RequestSubmitter
        Submits a Gremlin script with request options and blocks until the response is received.
        Specified by:
        submit in interface RequestSubmitter
        Parameters:
        gremlin - the Gremlin script to execute
        options - the options to supply for this request
        Returns:
        the results of the script execution