Class ResultSet
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.driver.ResultSet
-
public final class ResultSet extends Object implements Iterable<Result>
AResultSet
is returned from the submission of a Gremlin script to the server and represents the results provided by the server. The results from the server are streamed into theResultSet
and therefore may not be available immediately. As such,ResultSet
provides access to a a number of functions that help to work with the asynchronous nature of the data streaming back. Data from results is stored in anResult
which can be used to retrieve the item once it is on the client side. Note that aResultSet
is a forward-only stream only so depending on how the methods are called and interacted with, it is possible to return partial bits of the total response (e.g. callingone()
followed byall()
will make it so that theList
of results returned fromall()
have oneResult
missing from the total set as it was already retrieved byone()
. This class is not thread-safe.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
-
Constructor Summary
Constructors Constructor Description ResultSet(org.apache.tinkerpop.gremlin.driver.ResultQueue resultQueue, ExecutorService executor, CompletableFuture<Void> readCompleted, org.apache.tinkerpop.gremlin.util.message.RequestMessage originalRequestMessage, Host host)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<List<Result>>
all()
The returnedCompletableFuture
completes when all reads are complete for this request and the entire result has been accounted for on the client.boolean
allItemsAvailable()
Determines if all items have been returned to the client.CompletableFuture<Void>
allItemsAvailableAsync()
Returns a future that will complete when all items have been returned from the server.int
getAvailableItemCount()
Gets the number of items available on the client.Host
getHost()
org.apache.tinkerpop.gremlin.util.message.RequestMessage
getOriginalRequestMessage()
Iterator<Result>
iterator()
Returns a blocking iterator of the items streaming from the server to the client.Result
one()
Get the nextResult
from the stream, blocking until one is available.CompletableFuture<List<Result>>
some(int items)
The returnedCompletableFuture
completes when the number of items specified are available.CompletableFuture<Map<String,Object>>
statusAttributes()
Returns a future that will complete whenallItemsAvailable()
istrue
and will contain the attributes from the response.Stream<Result>
stream()
Stream items with a blocking iterator.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
ResultSet
public ResultSet(org.apache.tinkerpop.gremlin.driver.ResultQueue resultQueue, ExecutorService executor, CompletableFuture<Void> readCompleted, org.apache.tinkerpop.gremlin.util.message.RequestMessage originalRequestMessage, Host host)
-
-
Method Detail
-
getOriginalRequestMessage
public org.apache.tinkerpop.gremlin.util.message.RequestMessage getOriginalRequestMessage()
-
getHost
public Host getHost()
-
statusAttributes
public CompletableFuture<Map<String,Object>> statusAttributes()
Returns a future that will complete whenallItemsAvailable()
istrue
and will contain the attributes from the response.
-
allItemsAvailable
public boolean allItemsAvailable()
Determines if all items have been returned to the client.
-
allItemsAvailableAsync
public CompletableFuture<Void> allItemsAvailableAsync()
Returns a future that will complete when all items have been returned from the server.
-
getAvailableItemCount
public int getAvailableItemCount()
Gets the number of items available on the client.
-
some
public CompletableFuture<List<Result>> some(int items)
The returnedCompletableFuture
completes when the number of items specified are available. The number returned will be equal to or less than that number. They will only be less if the stream is completed and there are less than that number specified available.
-
all
public CompletableFuture<List<Result>> all()
The returnedCompletableFuture
completes when all reads are complete for this request and the entire result has been accounted for on the client. While this method is named "all" it really refers to retrieving all remaining items in the set. For large result sets it is preferred to useIterator
orStream
options, as the results will be held in memory at once.
-
iterator
public Iterator<Result> iterator()
Returns a blocking iterator of the items streaming from the server to the client. ThisIterator
will consume results as they arrive and leaving theResultSet
empty when complete. The returnedIterator
does not support theIterator.remove()
method.
-
-