Class Client
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.driver.Client
-
- Direct Known Subclasses:
Client.AliasClusteredClient
,Client.ClusteredClient
,Client.SessionedClient
public abstract class Client extends Object
AClient
is constructed from aCluster
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. TheClient
is designed to be re-used and shared across threads.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Client.AliasClusteredClient
Uses aClient.ClusteredClient
that rebinds requests to a specifiedGraph
orTraversalSource
instances on the server-side.static class
Client.ClusteredClient
AClient
implementation that does not operate in a session.static class
Client.SessionedClient
AClient
implementation that operates in the context of a session.static class
Client.SessionSettings
Settings for aClient
that involve a session.static class
Client.Settings
Settings given toCluster.connect(Client.Settings)
that configures how aClient
will behave.
-
Field Summary
Fields Modifier and Type Field Description protected Cluster
cluster
protected boolean
initialized
protected Client.Settings
settings
static String
TOO_MANY_IN_FLIGHT_REQUESTS
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Client
alias(String graphOrTraversalSource)
Create a newClient
that aliases the specifiedGraph
orTraversalSource
name on the server to a variable called "g" for the context of the requests made through thatClient
.Client
alias(Map<String,String> aliases)
Creates aClient
that supplies the specified set of aliases, thus allowing the user to re-name one or more globally definedGraph
orTraversalSource
server bindings for the context of the createdClient
.RequestMessage.Builder
buildMessage(RequestMessage.Builder builder)
Makes any initial changes to the builder and returns the constructedRequestMessage
.protected abstract org.apache.tinkerpop.gremlin.driver.Connection
chooseConnection(RequestMessage msg)
Chooses aConnection
to write the message to.void
close()
Closes the client by making a synchronous call tocloseAsync()
.abstract CompletableFuture<Void>
closeAsync()
Asynchronous close of theClient
.Cluster
getCluster()
Gets theCluster
that spawned thisClient
.Client.Settings
getSettings()
Gets theClient.Settings
.Client
init()
Initializes the client which typically means that a connection is established to the server.protected abstract void
initializeImplementation()
Called in theinit()
method.abstract boolean
isClosing()
protected Map<String,String>
makeDefaultAliasMap(String graphOrTraversalSource)
ResultSet
submit(String gremlin)
Submits a Gremlin script to the server and returns aResultSet
once the write of the request is complete.ResultSet
submit(String gremlin, Map<String,Object> parameters)
Submits a Gremlin script and bound parameters to the server and returns aResultSet
once the write of the request is complete.ResultSet
submit(String gremlin, RequestOptions options)
Submits a Gremlin script to the server and returns aResultSet
once the write of the request is complete.ResultSet
submit(Bytecode bytecode)
Submit aBytecode
to the server for remote execution.ResultSet
submit(Bytecode bytecode, RequestOptions options)
A version ofsubmit(Bytecode)
which provides the ability to set per-request options.ResultSet
submit(Traversal traversal)
Submit aTraversal
to the server for remote execution.Results are returned asTraverser
instances and are therefore bulked, meaning that to properly iterate the contents of the result eachTraverser.bulk()
must be examined to determine the number of times that object should be presented in iteration.CompletableFuture<ResultSet>
submitAsync(String gremlin)
The asynchronous version ofsubmit(String)
where the returned future will complete when the write of the request completes.CompletableFuture<ResultSet>
submitAsync(String gremlin, String graphOrTraversalSource, Map<String,Object> parameters)
Deprecated.As of release 3.4.0, replaced bysubmitAsync(String, RequestOptions)
.CompletableFuture<ResultSet>
submitAsync(String gremlin, Map<String,Object> parameters)
The asynchronous version ofsubmit(String, Map)
} where the returned future will complete when the write of the request completes.CompletableFuture<ResultSet>
submitAsync(String gremlin, Map<String,String> aliases, Map<String,Object> parameters)
Deprecated.As of release 3.4.0, replaced bysubmitAsync(String, RequestOptions)
.CompletableFuture<ResultSet>
submitAsync(String gremlin, RequestOptions options)
The asynchronous version ofsubmit(String, RequestOptions)
} where the returned future will complete when the write of the request completes.CompletableFuture<ResultSet>
submitAsync(RequestMessage msg)
A low-level method that allows the submission of a manually constructedRequestMessage
.CompletableFuture<ResultSet>
submitAsync(Bytecode bytecode)
An asynchronous version ofsubmit(Traversal)
.CompletableFuture<ResultSet>
submitAsync(Bytecode bytecode, RequestOptions options)
A version ofsubmit(Bytecode)
which provides the ability to set per-request options.CompletableFuture<ResultSet>
submitAsync(Traversal traversal)
An asynchronous version ofsubmit(Traversal)
.
-
-
-
Field Detail
-
TOO_MANY_IN_FLIGHT_REQUESTS
public static final String TOO_MANY_IN_FLIGHT_REQUESTS
- See Also:
- Constant Field Values
-
cluster
protected final Cluster cluster
-
initialized
protected volatile boolean initialized
-
settings
protected final Client.Settings settings
-
-
Method Detail
-
buildMessage
public RequestMessage.Builder buildMessage(RequestMessage.Builder builder)
Makes any initial changes to the builder and returns the constructedRequestMessage
. Implementers may choose to override this message to append data to the request before sending. By default, this method will simply return thebuilder
passed in by the caller.
-
initializeImplementation
protected abstract void initializeImplementation()
Called in theinit()
method.
-
chooseConnection
protected abstract org.apache.tinkerpop.gremlin.driver.Connection chooseConnection(RequestMessage msg) throws TimeoutException, ConnectionException
Chooses aConnection
to write the message to.- Throws:
TimeoutException
ConnectionException
-
closeAsync
public abstract CompletableFuture<Void> closeAsync()
Asynchronous close of theClient
.
-
alias
public Client alias(String graphOrTraversalSource)
Create a newClient
that aliases the specifiedGraph
orTraversalSource
name on the server to a variable called "g" for the context of the requests made through thatClient
.- Parameters:
graphOrTraversalSource
- rebinds the specified global Gremlin Server variable to "g"
-
alias
public Client alias(Map<String,String> aliases)
Creates aClient
that supplies the specified set of aliases, thus allowing the user to re-name one or more globally definedGraph
orTraversalSource
server bindings for the context of the createdClient
.
-
submit
public ResultSet submit(Traversal traversal)
Submit aTraversal
to the server for remote execution.Results are returned asTraverser
instances and are therefore bulked, meaning that to properly iterate the contents of the result eachTraverser.bulk()
must be examined to determine the number of times that object should be presented in iteration.
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(Traversal traversal)
An asynchronous version ofsubmit(Traversal)
. Results are returned asTraverser
instances and are therefore bulked, meaning that to properly iterate the contents of the result eachTraverser.bulk()
must be examined to determine the number of times that object should be presented in iteration.
-
submit
public ResultSet submit(Bytecode bytecode)
Submit aBytecode
to the server for remote execution. Results are returned asTraverser
instances and are therefore bulked, meaning that to properly iterate the contents of the result eachTraverser.bulk()
must be examined to determine the number of times that object should be presented in iteration.
-
submit
public ResultSet submit(Bytecode bytecode, RequestOptions options)
A version ofsubmit(Bytecode)
which provides the ability to set per-request options.- Parameters:
bytecode
- request in the form of gremlinBytecode
options
- for the request- See Also:
submit(Bytecode)
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(Bytecode bytecode)
An asynchronous version ofsubmit(Traversal)
. Results are returned asTraverser
instances and are therefore bulked, meaning that to properly iterate the contents of the result eachTraverser.bulk()
must be examined to determine the number of times that object should be presented in iteration.
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(Bytecode bytecode, RequestOptions options)
A version ofsubmit(Bytecode)
which provides the ability to set per-request options.- Parameters:
bytecode
- request in the form of gremlinBytecode
options
- for the request- See Also:
submitAsync(Bytecode)
-
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 aResultSet
once the write of the request is complete.- Parameters:
gremlin
- the gremlin script to execute
-
submit
public ResultSet submit(String gremlin, Map<String,Object> parameters)
Submits a Gremlin script and bound parameters to the server and returns aResultSet
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 tosubmit(String)
. Parameterized scripts will perform better.- Parameters:
gremlin
- the gremlin script to executeparameters
- a map of parameters that will be bound to the script on execution
-
submit
public ResultSet submit(String gremlin, RequestOptions options)
Submits a Gremlin script to the server and returns aResultSet
once the write of the request is complete.- Parameters:
gremlin
- the gremlin script to executeoptions
- for the request
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(String gremlin)
The asynchronous version ofsubmit(String)
where the returned future will complete when the write of the request completes.- Parameters:
gremlin
- the gremlin script to execute
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(String gremlin, Map<String,Object> parameters)
The asynchronous version ofsubmit(String, Map)
} where the returned future will complete when the write of the request completes.- Parameters:
gremlin
- the gremlin script to executeparameters
- a map of parameters that will be bound to the script on execution
-
submitAsync
@Deprecated public CompletableFuture<ResultSet> submitAsync(String gremlin, String graphOrTraversalSource, Map<String,Object> parameters)
Deprecated.As of release 3.4.0, replaced bysubmitAsync(String, RequestOptions)
.The asynchronous version ofsubmit(String, Map)
} where the returned future will complete when the write of the request completes.- Parameters:
gremlin
- the gremlin script to executeparameters
- a map of parameters that will be bound to the script on executiongraphOrTraversalSource
- rebinds the specified global Gremlin Server variable to "g"
-
submitAsync
@Deprecated public CompletableFuture<ResultSet> submitAsync(String gremlin, Map<String,String> aliases, Map<String,Object> parameters)
Deprecated.As of release 3.4.0, replaced bysubmitAsync(String, RequestOptions)
.The asynchronous version ofsubmit(String, Map)
} where the returned future will complete when the write of the request completes.- Parameters:
gremlin
- the gremlin script to executeparameters
- a map of parameters that will be bound to the script on executionaliases
- aliases the specified global Gremlin Server variable some other name that then be used in the script where the key is the alias name and the value represents the global variable on the server
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(String gremlin, RequestOptions options)
The asynchronous version ofsubmit(String, RequestOptions)
} where the returned future will complete when the write of the request completes.- Parameters:
gremlin
- the gremlin script to executeoptions
- the options to supply for this request
-
submitAsync
public CompletableFuture<ResultSet> submitAsync(RequestMessage msg)
A low-level method that allows the submission of a manually constructedRequestMessage
.
-
isClosing
public abstract boolean isClosing()
-
close
public void close()
Closes the client by making a synchronous call tocloseAsync()
.
-
getSettings
public Client.Settings getSettings()
Gets theClient.Settings
.
-
-