public class Connection
extends java.lang.Object
implements java.io.Closeable
This object is thread-safe.
| Modifier and Type | Class and Description |
|---|---|
static class |
Connection.Builder
Builder should be used to build a Connection instance.
|
| Modifier and Type | Field and Description |
|---|---|
protected @Nullable java.lang.String |
dbname |
protected @NotNull Result.FetchMode |
defaultFetchMode |
protected @NotNull java.lang.String |
hostname |
protected @NotNull java.util.concurrent.atomic.AtomicLong |
nextToken |
protected @Nullable java.lang.String |
password |
protected boolean |
persistentThreads |
protected int |
port |
protected @Nullable ResponsePump |
pump |
protected ResponsePump.Factory |
pumpFactory |
protected @Nullable ConnectionSocket |
socket |
protected ConnectionSocket.Factory |
socketFactory |
protected @Nullable javax.net.ssl.SSLContext |
sslContext |
protected @Nullable java.lang.Long |
timeout |
protected @NotNull java.util.Set<Result<?>> |
tracked |
protected boolean |
unwrapLists |
protected @Nullable java.lang.String |
user |
protected @NotNull java.util.concurrent.locks.Lock |
writeLock |
| Constructor and Description |
|---|
Connection(@NotNull Connection.Builder b)
Creates a new connection based on a
Connection.Builder. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
|
void |
close(boolean shouldNoreplyWait)
|
@NotNull java.util.concurrent.CompletableFuture<java.lang.Void> |
closeAsync()
Closes this connection asynchronously, closing all
Results, the ResponsePump and the ConnectionSocket. |
@NotNull java.util.concurrent.CompletableFuture<java.lang.Void> |
closeAsync(boolean shouldNoreplyWait)
Closes this connection asynchronously, closing all
Results, the ResponsePump and the ConnectionSocket. |
void |
closeResults()
Closes all
Results currently opened. |
@NotNull Connection |
connect()
Begins the socket connection to the server.
|
@NotNull java.util.concurrent.CompletableFuture<Connection> |
connectAsync()
Begins the socket connection to the server asynchronously.
|
protected @NotNull java.util.concurrent.CompletableFuture<ConnectionSocket> |
createSocketAsync()
Detects if the connection socket supports async creation or wraps it before returning.
|
@Nullable java.lang.String |
db()
Gets the default database of the server.
|
protected void |
handleOptArgs(@NotNull OptArgs optArgs)
Handle optArgs before sending to the server.
|
boolean |
hasOngoingQueries()
Checks if there are any ongoing query.
|
boolean |
isOpen()
Checks if the connection is open.
|
protected void |
keepTrackOf(@NotNull Result<?> r)
Callback method from
Result, signals that this connection should keep track of this result. |
protected void |
loseTrackOf(@NotNull Result<?> r)
Callback method from
Result, signals that this connection should no long keep track of this result. |
void |
noreplyWait()
Runs a
noreply_wait query to the server and awaits it. |
@NotNull java.util.concurrent.CompletableFuture<java.lang.Void> |
noreplyWaitAsync()
Runs a
noreply_wait query to the server and awaits it asynchronously. |
@NotNull Connection |
reconnect()
Closes and reconnects to the server.
|
@NotNull Connection |
reconnect(boolean noreplyWait)
Closes and reconnects to the server.
|
@NotNull java.util.concurrent.CompletableFuture<Connection> |
reconnectAsync()
Closes and reconnects to the server.
|
@NotNull java.util.concurrent.CompletableFuture<Connection> |
reconnectAsync(boolean noreplyWait)
Closes and reconnects to the server asynchronously.
|
<T> @NotNull Result<T> |
run(@NotNull ReqlAst term,
@NotNull OptArgs optArgs,
@Nullable Result.FetchMode fetchMode,
@Nullable java.lang.Boolean unwrap,
@Nullable com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Runs a ReQL query with options
optArgs, the specified fetchMode and returns the result, with the
values converted to the type of TypeReference<T> |
<T> @NotNull java.util.concurrent.CompletableFuture<Result<T>> |
runAsync(@NotNull ReqlAst term,
@NotNull OptArgs optArgs,
@Nullable Result.FetchMode fetchMode,
@Nullable java.lang.Boolean unwrap,
@Nullable com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Runs a ReQL query with options
optArgs, the specified fetchMode and returns the result
asynchronously, with the values converted to the type of TypeReference<T> |
void |
runNoReply(@NotNull ReqlAst term,
@NotNull OptArgs optArgs)
Runs this query via connection
conn with options optArgs without awaiting the response. |
protected <T> @NotNull java.util.concurrent.CompletableFuture<Result<T>> |
runQuery(@NotNull Query query,
@Nullable Result.FetchMode fetchMode,
@Nullable java.lang.Boolean unwrap,
@Nullable com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
Sents a query to the server and returns a
CompletableFuture which completes with a result. |
protected void |
runQueryNoreply(@NotNull Query query)
Writes a query without waiting for a response
|
protected @NotNull java.util.concurrent.CompletableFuture<Response> |
sendContinue(long token)
Sends a CONTINUE query.
|
protected @NotNull java.util.concurrent.CompletableFuture<Response> |
sendQuery(@NotNull Query query)
Writes a query and returns a completable future.
|
protected void |
sendStop(long token)
Sends a STOP query.
|
@NotNull Server |
server()
Runs a
server_info query to the server and returns the server info. |
@NotNull java.util.concurrent.CompletableFuture<Server> |
serverAsync()
Runs a
server_info query to the server and returns the server info asynchronously. |
@NotNull Connection |
use(@Nullable java.lang.String db)
Sets the default database of the server.
|
@NotNull protected final @NotNull java.lang.String hostname
protected final int port
@Nullable protected final @Nullable java.lang.String user
@Nullable protected final @Nullable java.lang.String password
@Nullable protected final @Nullable java.lang.Long timeout
@Nullable protected final @Nullable javax.net.ssl.SSLContext sslContext
@NotNull protected final ConnectionSocket.Factory socketFactory
@NotNull protected final ResponsePump.Factory pumpFactory
@NotNull protected final @NotNull Result.FetchMode defaultFetchMode
protected final boolean unwrapLists
protected final boolean persistentThreads
@NotNull protected final @NotNull java.util.concurrent.atomic.AtomicLong nextToken
@NotNull protected final @NotNull java.util.Set<Result<?>> tracked
@NotNull protected final @NotNull java.util.concurrent.locks.Lock writeLock
@Nullable protected @Nullable java.lang.String dbname
@Nullable protected @Nullable ConnectionSocket socket
@Nullable protected @Nullable ResponsePump pump
public Connection(@NotNull
@NotNull Connection.Builder b)
Connection.Builder.b - the connection builder@Nullable public @Nullable java.lang.String db()
Connection.Builder.db(String) or use(String)@NotNull public @NotNull Connection use(@Nullable @Nullable java.lang.String db)
db - the new current default database.public boolean isOpen()
@NotNull public @NotNull java.util.concurrent.CompletableFuture<Connection> connectAsync()
CompletableFuture which completes with itself, once connected.@NotNull public @NotNull Connection connect()
@NotNull public @NotNull java.util.concurrent.CompletableFuture<Connection> reconnectAsync()
CompletableFuture which completes with itself, once reconnected.@NotNull public @NotNull java.util.concurrent.CompletableFuture<Connection> reconnectAsync(boolean noreplyWait)
noreplyWait - if closing should send a noreplyWait() before closing.CompletableFuture which completes with itself, once reconnected.@NotNull public @NotNull Connection reconnect()
@NotNull public @NotNull Connection reconnect(boolean noreplyWait)
noreplyWait - if closing should send a noreplyWait() before closing.@NotNull public <T> @NotNull java.util.concurrent.CompletableFuture<Result<T>> runAsync(@NotNull @NotNull ReqlAst term, @NotNull @NotNull OptArgs optArgs, @Nullable @Nullable Result.FetchMode fetchMode, @Nullable @Nullable java.lang.Boolean unwrap, @Nullable @Nullable com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
optArgs, the specified fetchMode and returns the result
asynchronously, with the values converted to the type of TypeReference<T>T - The type of resultterm - The ReQL termoptArgs - The options to run this query withfetchMode - The fetch mode to use in partial sequencesunwrap - Override for the connection's unwrapLists settingtypeRef - The type to convert to@NotNull public <T> @NotNull Result<T> run(@NotNull @NotNull ReqlAst term, @NotNull @NotNull OptArgs optArgs, @Nullable @Nullable Result.FetchMode fetchMode, @Nullable @Nullable java.lang.Boolean unwrap, @Nullable @Nullable com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
optArgs, the specified fetchMode and returns the result, with the
values converted to the type of TypeReference<T>T - The type of resultterm - The ReQL termoptArgs - The options to run this query withfetchMode - The fetch mode to use in partial sequencesunwrap - Override for the connection's unwrapLists settingtypeRef - The type to convert to@NotNull public @NotNull java.util.concurrent.CompletableFuture<Server> serverAsync()
server_info query to the server and returns the server info asynchronously.@NotNull public @NotNull Server server()
server_info query to the server and returns the server info.@NotNull public @NotNull java.util.concurrent.CompletableFuture<java.lang.Void> noreplyWaitAsync()
noreply_wait query to the server and awaits it asynchronously.CompletableFuture you can await.public void noreplyWait()
noreply_wait query to the server and awaits it.public void runNoReply(@NotNull
@NotNull ReqlAst term,
@NotNull
@NotNull OptArgs optArgs)
conn with options optArgs without awaiting the response.term - The ReQL termoptArgs - The options to run this query with@NotNull public @NotNull java.util.concurrent.CompletableFuture<java.lang.Void> closeAsync()
Results, the ResponsePump and the ConnectionSocket.CompletableFuture which completes when everything is closed.@NotNull public @NotNull java.util.concurrent.CompletableFuture<java.lang.Void> closeAsync(boolean shouldNoreplyWait)
Results, the ResponsePump and the ConnectionSocket.shouldNoreplyWait - If the connection should noreply_wait before closingCompletableFuture which completes when everything is closed.public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic void close(boolean shouldNoreplyWait)
shouldNoreplyWait - If the connection should noreply_wait before closingpublic void closeResults()
Results currently opened.public boolean hasOngoingQueries()
true if there's an ongoing query that will be closed if this connection is closed.protected void sendStop(long token)
Result partial sequences.token - the response token.@NotNull protected @NotNull java.util.concurrent.CompletableFuture<Response> sendContinue(long token)
Result partial sequences.token - the response token.protected void keepTrackOf(@NotNull
@NotNull Result<?> r)
Result, signals that this connection should keep track of this result.
Tracked results can be closed using close() or closeResults().r - the result to be tracked.protected void loseTrackOf(@NotNull
@NotNull Result<?> r)
Result, signals that this connection should no long keep track of this result.
The result probably finished or was closed.r - the result to be tracked.@NotNull protected @NotNull java.util.concurrent.CompletableFuture<Response> sendQuery(@NotNull @NotNull Query query)
connect()).query - the query to execute.protected void runQueryNoreply(@NotNull
@NotNull Query query)
query - the query to execute.@NotNull protected <T> @NotNull java.util.concurrent.CompletableFuture<Result<T>> runQuery(@NotNull @NotNull Query query, @Nullable @Nullable Result.FetchMode fetchMode, @Nullable @Nullable java.lang.Boolean unwrap, @Nullable @Nullable com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
CompletableFuture which completes with a result.
Runs a ReQL query with options optArgs, the specified fetchMode and returns the result, with the
values converted to the type of TypeReference<T>T - The type of resultquery - The queryfetchMode - The fetch mode to use in partial sequencesunwrap - Override for the connection's unwrapLists settingtypeRef - The type to convert toCompletableFuture which completes with the result of the query.protected void handleOptArgs(@NotNull
@NotNull OptArgs optArgs)
optArgs - the optArgs.@NotNull protected @NotNull java.util.concurrent.CompletableFuture<ConnectionSocket> createSocketAsync()
CompletableFuture which will complete with a new ConnectionSocket.