Class Client

java.lang.Object
org.apache.tinkerpop.gremlin.driver.Client
All Implemented Interfaces:
RequestSubmitter, RequestSubmitterAsync
Direct Known Subclasses:
Client.AliasClusteredClient, Client.ClusteredClient, Client.PinnedClient

public abstract class Client extends Object implements RequestSubmitter, RequestSubmitterAsync
A Client is constructed from a Cluster and represents a way to send messages to Gremlin Server. This class itself is a base class as there are different implementations that provide differing kinds of functionality. See the implementations for specifics on their individual usage.

The Client is designed to be re-used and shared across threads.

Author:
Stephen Mallette (http://stephen.genoprime.com)
  • Field Details

    • TOO_MANY_IN_FLIGHT_REQUESTS

      public static final String TOO_MANY_IN_FLIGHT_REQUESTS
      See Also:
    • cluster

      protected final Cluster cluster
    • initialized

      protected volatile boolean initialized
  • Method Details

    • buildMessage

      public RequestMessage.Builder buildMessage(RequestMessage.Builder builder)
      Makes any initial changes to the builder and returns the constructed RequestMessage. Implementers may choose to override this message to append data to the request before sending. By default, this method will simply return the builder passed in by the caller.
    • initializeImplementation

      protected abstract void initializeImplementation()
      Called in the init() method.
    • chooseConnection

      protected abstract org.apache.tinkerpop.gremlin.driver.Connection chooseConnection(RequestMessage msg) throws TimeoutException, ConnectionException
      Chooses a Connection to write the message to.
      Throws:
      TimeoutException
      ConnectionException
    • closeAsync

      public abstract CompletableFuture<Void> closeAsync()
      Asynchronous close of the Client.
    • alias

      public Client alias(String graphOrTraversalSource)
      Create a new Client that aliases the specified Graph or TraversalSource name on the server to a variable called "g" for the context of the requests made through that Client.
      Parameters:
      graphOrTraversalSource - rebinds the specified global Gremlin Server variable to "g"
    • init

      public Client init()
      Initializes the client which typically means that a connection is established to the server. Depending on the implementation and configuration this blocking call may take some time. This method will be called automatically if it is not called directly and multiple calls will not have effect.
    • submit

      public ResultSet submit(String gremlin)
      Submits a Gremlin script to the server and returns a ResultSet once the write of the request is complete.
      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)
      Submits a Gremlin script and bound parameters to the server and returns a ResultSet once the write of the request is complete. If a script is to be executed repeatedly with slightly different arguments, prefer this method to concatenating a Gremlin script from dynamically produced strings and sending it to submit(String). Parameterized scripts will 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)
      Submits a Gremlin script to the server and returns a ResultSet once the write of the request is complete.
      Specified by:
      submit in interface RequestSubmitter
      Parameters:
      gremlin - the gremlin script to execute
      options - for the request
      Returns:
      the results of the script execution
    • submitAsync

      public CompletableFuture<ResultSet> submitAsync(String gremlin)
      The asynchronous version of submit(String) where the returned future will complete when the write of the request completes.
      Specified by:
      submitAsync in interface RequestSubmitterAsync
      Parameters:
      gremlin - the gremlin script to execute
      Returns:
      a future that completes with the results when the request write is complete
    • submitAsync

      public CompletableFuture<ResultSet> submitAsync(String gremlin, Map<String,Object> parameters)
      The asynchronous version of submit(String, Map)} where the returned future will complete when the write of the request completes.
      Specified by:
      submitAsync in interface RequestSubmitterAsync
      Parameters:
      gremlin - the gremlin script to execute
      parameters - a map of parameters that will be bound to the script on execution
      Returns:
      a future that completes with the results when the request write is complete
    • submitAsync

      @Deprecated public CompletableFuture<ResultSet> submitAsync(String gremlin, String graphOrTraversalSource, Map<String,Object> parameters)
      Deprecated.
      As of release 3.4.0, replaced by submitAsync(String, RequestOptions).
      The asynchronous version of submit(String, Map)} where the returned future will complete when the write of the request completes.
      Parameters:
      gremlin - the gremlin script to execute
      parameters - a map of parameters that will be bound to the script on execution
      graphOrTraversalSource - rebinds the specified global Gremlin Server variable to "g"
    • submitAsync

      public CompletableFuture<ResultSet> submitAsync(String gremlin, RequestOptions options)
      The asynchronous version of submit(String, RequestOptions)} where the returned future will complete when the write of the request completes.
      Specified by:
      submitAsync in interface RequestSubmitterAsync
      Parameters:
      gremlin - the gremlin script to execute
      options - the options to supply for this request
      Returns:
      a future that completes with the results when the request write is complete
    • submitAsync

      public CompletableFuture<ResultSet> submitAsync(RequestMessage msg)
      A low-level method that allows the submission of a manually constructed RequestMessage.
    • isClosing

      public abstract boolean isClosing()
    • close

      public void close()
      Closes the client by making a synchronous call to closeAsync().
    • getCluster

      public Cluster getCluster()
      Gets the Cluster that spawned this Client.
    • chooseRandomHost

      protected Host chooseRandomHost()