Class ResultSet
java.lang.Object
org.apache.tinkerpop.gremlin.driver.ResultSet
A
ResultSet 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 the ResultSet and
therefore may not be available immediately. As such, ResultSet provides access to a number
of functions that help to work with the asynchronous nature of the data streaming back. Data from results
is stored in an Result which can be used to retrieve the item once it is on the client side.
Note that a ResultSet 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. calling one() followed
by all() will make it so that the List of results returned from all() have one
Result missing from the total set as it was already retrieved by one().
This class is not thread-safe.- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
Constructor Summary
ConstructorsConstructorDescriptionResultSet(ExecutorService executor, RequestMessage originalRequestMessage, Host host) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds aResultto the queue which will be later read by consumers.all()The returnedCompletableFuturecompletes when all reads are complete for this request and the entire result has been accounted for on the client.booleanDetermines if all items have been returned to the client.Returns a future that will complete when all items have been returned from the server.intGets the number of items available on the client.getHost()Returns a future that completes once the server's response headers have been received - that is, once the request has made a full round trip to the server and the server has begun responding - without waiting for the entire body.iterator()Returns a blocking iterator of the items streaming from the server to the client.voidMarks the result stream as complete.voidMarks the result stream as failed with an error.voidMarks the response headers as received.one()Get the nextResultfrom the stream, blocking until one is available.some(int items) The returnedCompletableFuturecompletes when the number of items specified are available.stream()Stream items with a blocking iterator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ResultSet
-
-
Method Details
-
getOriginalRequestMessage
-
getHost
-
allItemsAvailable
public boolean allItemsAvailable()Determines if all items have been returned to the client. -
allItemsAvailableAsync
Returns a future that will complete when all items have been returned from the server. -
headersReceivedAsync
Returns a future that completes once the server's response headers have been received - that is, once the request has made a full round trip to the server and the server has begun responding - without waiting for the entire body. Used by remote transactions to block on submission just long enough to guarantee server-side ordering relative to a subsequent request, while still streaming the body lazily. -
getAvailableItemCount
public int getAvailableItemCount()Gets the number of items available on the client. -
one
Get the nextResultfrom the stream, blocking until one is available. -
some
The returnedCompletableFuturecompletes 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
The returnedCompletableFuturecompletes 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 useIteratororStreamoptions, as the results will be held in memory at once. -
stream
Stream items with a blocking iterator. -
iterator
Returns a blocking iterator of the items streaming from the server to the client. ThisIteratorwill consume results as they arrive and leaving theResultSetempty when complete. The returnedIteratordoes not support theIterator.remove()method. -
add
Adds aResultto the queue which will be later read by consumers.- Parameters:
result- a return value from the traversal or script submitted for execution
-
markHeadersReceived
public void markHeadersReceived()Marks the response headers as received. Called by the streaming decoder the moment the server's response header is decoded, before any body chunks are processed. Idempotent and safe to call more than once. On the non-streaming path there is no separate header event - the aggregator coalesces the whole response - so this is instead tripped as a backstop bymarkComplete()/markError(Throwable). -
markComplete
public void markComplete()Marks the result stream as complete. -
markError
Marks the result stream as failed with an error.- Parameters:
throwable- the error that occurred
-