Class HttpRemoteTransaction
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.driver.remote.HttpRemoteTransaction
-
- All Implemented Interfaces:
AutoCloseable,RemoteTransaction,RequestSubmitter,Transaction
public class HttpRemoteTransaction extends Object implements RemoteTransaction
ATransactionimplementation 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
Transaction.CLOSE_BEHAVIOR, Transaction.Exceptions, Transaction.READ_WRITE_BEHAVIOR, Transaction.Status, Transaction.Symbols
-
-
Field Summary
Fields Modifier and Type Field Description protected Consumer<Transaction>closeConsumer-
Fields inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
NO_OP
-
-
Constructor Summary
Constructors Constructor Description HttpRemoteTransaction(Client.PinnedClient pinnedClient, String graphAlias)Creates a new HTTP transaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTransactionListener(Consumer<Transaction.Status> listener)Adds a listener that is called back with a status when a commit or rollback is successful.<T extends TraversalSource>
Tbegin(Class<T> traversalSourceClass)Starts a transaction and returns a traversal source bound to it.voidclearTransactionListeners()Removes all transaction listeners.voidclose()Closes the transaction where the default close behavior defined by {Transaction.onClose(Consumer)} will be executed.voidcommit()Commits the transaction.StringgetTransactionId()Returns the server-generated transaction ID, ornullif the transaction has not yet been started viabegin(Class).booleanisOpen()Determines if a transaction is currently open.TransactiononClose(Consumer<Transaction> consumer)Describes what happens to a transaction on a call toGraph.close().TransactiononReadWrite(Consumer<Transaction> consumer)Describes how a transaction is started when a read or a write occurs.voidopen()Not supported for remote transactions.voidreadWrite()An internal function that signals a read or a write has occurred - not meant to be called directly by end users.voidremoveTransactionListener(Consumer<Transaction.Status> listener)Removes a transaction listener.voidrollback()Rolls back the transaction.ResultSetsubmit(String gremlin)Submits a Gremlin script and blocks until the response is received.ResultSetsubmit(String gremlin, Map<String,Object> parameters)Submits a Gremlin script with bound parameters and blocks until the response is received.ResultSetsubmit(String gremlin, RequestOptions options)Submits a Gremlin script with request options and blocks until the response is received.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
begin, createThreadedTx
-
-
-
-
Field Detail
-
closeConsumer
protected Consumer<Transaction> closeConsumer
-
-
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 accessgraphAlias- the graph/traversal source alias (e.g., "g")- Throws:
NoHostAvailableException- if no hosts are available in the cluster
-
-
Method Detail
-
open
public void open()
Not supported for remote transactions. Usebegin(Class)instead.- Specified by:
openin interfaceTransaction- Throws:
UnsupportedOperationException- always
-
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:
beginin interfaceTransaction- 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 startedRuntimeException- if the transaction fails to begin
-
commit
public void commit()
Commits the transaction.Sends
g.tx().commit()to the server and closes the transaction.- Specified by:
commitin interfaceTransaction- Throws:
IllegalStateException- if the transaction is not openTransactionException- if the commit fails
-
rollback
public void rollback()
Rolls back the transaction.Sends
g.tx().rollback()to the server and closes the transaction.- Specified by:
rollbackin interfaceTransaction- Throws:
IllegalStateException- if the transaction is not openTransactionException- if the rollback fails
-
getTransactionId
public String getTransactionId()
Returns the server-generated transaction ID, ornullif the transaction has not yet been started viabegin(Class).- Specified by:
getTransactionIdin interfaceRemoteTransaction- Returns:
- the transaction ID, or null if not yet begun
-
isOpen
public boolean isOpen()
Description copied from interface:TransactionDetermines if a transaction is currently open.- Specified by:
isOpenin interfaceTransaction
-
readWrite
public void readWrite()
Description copied from interface:TransactionAn internal function that signals a read or a write has occurred - not meant to be called directly by end users.- Specified by:
readWritein interfaceTransaction
-
close
public void close()
Description copied from interface:TransactionCloses the transaction where the default close behavior defined by {Transaction.onClose(Consumer)} will be executed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTransaction
-
onReadWrite
public Transaction onReadWrite(Consumer<Transaction> consumer)
Description copied from interface:TransactionDescribes how a transaction is started when a read or a write occurs. This value can be set using standard behaviors defined inTransaction.READ_WRITE_BEHAVIORor a mapperConsumerfunction.- Specified by:
onReadWritein interfaceTransaction
-
onClose
public Transaction onClose(Consumer<Transaction> consumer)
Description copied from interface:TransactionDescribes what happens to a transaction on a call toGraph.close(). This value can be set using standard behavior defined inTransaction.CLOSE_BEHAVIORor a mapperConsumerfunction.- Specified by:
onClosein interfaceTransaction
-
addTransactionListener
public void addTransactionListener(Consumer<Transaction.Status> listener)
Description copied from interface:TransactionAdds 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:
addTransactionListenerin interfaceTransaction
-
removeTransactionListener
public void removeTransactionListener(Consumer<Transaction.Status> listener)
Description copied from interface:TransactionRemoves a transaction listener.- Specified by:
removeTransactionListenerin interfaceTransaction
-
clearTransactionListeners
public void clearTransactionListeners()
Description copied from interface:TransactionRemoves all transaction listeners.- Specified by:
clearTransactionListenersin interfaceTransaction
-
submit
public ResultSet submit(String gremlin)
Description copied from interface:RequestSubmitterSubmits a Gremlin script and blocks until the response is received.- Specified by:
submitin interfaceRequestSubmitter- 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:RequestSubmitterSubmits 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:
submitin interfaceRequestSubmitter- Parameters:
gremlin- the Gremlin script to executeparameters- 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:RequestSubmitterSubmits a Gremlin script with request options and blocks until the response is received.- Specified by:
submitin interfaceRequestSubmitter- Parameters:
gremlin- the Gremlin script to executeoptions- the options to supply for this request- Returns:
- the results of the script execution
-
-