T - the type of the result.public class Result<T>
extends java.lang.Object
implements java.util.Iterator<T>, java.lang.Iterable<T>, java.io.Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
Result.FetchMode
The fetch mode to use on partial sequences.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.CompletableFuture<java.lang.Boolean> |
completed |
protected Connection |
connection |
protected Result.FetchMode |
fetchMode |
protected Internals.FormatOptions |
fmt |
protected Query |
query |
protected java.util.concurrent.BlockingQueue<java.lang.Object> |
rawQueue |
protected Response |
sourceResponse |
protected com.fasterxml.jackson.core.type.TypeReference<T> |
typeRef |
protected boolean |
unwrapLists |
| Constructor and Description |
|---|
Result(Connection connection,
Query query,
Response sourceResponse,
Result.FetchMode fetchMode,
boolean unwrapLists,
com.fasterxml.jackson.core.type.TypeReference<T> typeRef) |
| Modifier and Type | Method and Description |
|---|---|
int |
bufferedCount()
Gets the number of objects buffered and readily available.
|
void |
close()
Closes this Result.
|
<R,A> R |
collect(@NotNull java.util.stream.Collector<? super T,A,R> collector)
Collect all remaining results using the provided
Collector, fetching from the server if necessary, and
closes the Result.WARNING: If isFeed() is true, this may never return. |
long |
connectionToken()
Gets the connection token of this result.
|
protected Response |
currentResponse() |
protected int |
emitData(Response res) |
T |
first()
Returns the first object and closes the Result, discarding all other results.
|
void |
forEach(java.util.function.Consumer<? super T> action) |
void |
forEachRemaining(java.util.function.Consumer<? super T> action) |
protected void |
handleFirstResponse()
Function called on the first response.
|
boolean |
hasNext() |
boolean |
isFeed()
Gets if this Result is a feed.
|
@NotNull java.util.Iterator<T> |
iterator() |
protected void |
maybeContinue() |
T |
next() |
T |
next(long timeout,
java.util.concurrent.TimeUnit unit)
Returns the next element in the iteration, with a defined timeout.
|
protected void |
onConnectionClosed() |
@NotNull Result<T> |
overrideFetchMode(Result.FetchMode fetchMode)
Overrides the fetch mode for this Result.
|
@NotNull java.util.stream.Stream<T> |
parallelStream()
Creates a new parallel
Stream from the results, which closes this Result on completion. |
@Nullable Profile |
profile()
Gets the current's response Profile, if any.
|
@NotNull ResponseType |
responseType()
Returns the current responses' type.
|
T |
single()
Returns the first object and closes the Result, discarding all other results.
|
@NotNull java.util.stream.Stream<T> |
stream()
Creates a new sequential
Stream from the results, which closes this Result on completion. |
protected void |
throwOnCompleted() |
@NotNull java.util.List<T> |
toList()
Collect all remaining results to a list, fetching from the server if necessary, and closes the Result.
WARNING: If isFeed() is true, this may never return. |
java.lang.String |
toString() |
protected final Connection connection
protected final Query query
protected final Response sourceResponse
protected final com.fasterxml.jackson.core.type.TypeReference<T> typeRef
protected final Internals.FormatOptions fmt
protected final boolean unwrapLists
protected Result.FetchMode fetchMode
protected final java.util.concurrent.BlockingQueue<java.lang.Object> rawQueue
protected final java.util.concurrent.CompletableFuture<java.lang.Boolean> completed
public Result(Connection connection, Query query, Response sourceResponse, Result.FetchMode fetchMode, boolean unwrapLists, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
public long connectionToken()
public int bufferedCount()
public boolean isFeed()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseable@NotNull public @NotNull java.util.List<T> toList()
isFeed() is true, this may never return. This method changes the fetchMode
of this Result to Result.FetchMode.AGGRESSIVE to complete this as fast as possible.public <R,A> R collect(@NotNull
@NotNull java.util.stream.Collector<? super T,A,R> collector)
Collector, fetching from the server if necessary, and
closes the Result.isFeed() is true, this may never return. This method changes the fetchMode
of this Result to Result.FetchMode.AGGRESSIVE to complete this as fast as possible.A - the mutable accumulation type of the reduction operation (often hidden as an implementation detail)R - the result type of the reduction operationcollector - the collector@NotNull public @NotNull java.util.stream.Stream<T> stream()
Stream from the results, which closes this Result on completion.
isFeed() is true, this stream is possibly infinite. This method changes the
fetchMode of this Result to Result.FetchMode.AGGRESSIVE to complete this as fast as possible.@NotNull public @NotNull java.util.stream.Stream<T> parallelStream()
Stream from the results, which closes this Result on completion.
isFeed() is true, this stream is possibly infinite. This method changes the
fetchMode of this Result to Result.FetchMode.AGGRESSIVE to complete this as fast as possible.public boolean hasNext()
hasNext in interface java.util.Iterator<T>@Nullable public T next(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
timeout - how long to wait before giving up, in units of unitunit - a TimeUnit determining how to interpret the timeout parameterjava.util.NoSuchElementException - if the iteration has no more elementsjava.util.concurrent.TimeoutException - if the poll operation times out@Nullable public T first()
@Nullable public T single()
@NotNull public @NotNull java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>public void forEach(java.util.function.Consumer<? super T> action)
forEach in interface java.lang.Iterable<T>public void forEachRemaining(java.util.function.Consumer<? super T> action)
forEachRemaining in interface java.util.Iterator<T>@Nullable public @Nullable Profile profile()
@NotNull public @NotNull ResponseType responseType()
ResponseType of the current response.@NotNull public @NotNull Result<T> overrideFetchMode(Result.FetchMode fetchMode)
fetchMode - the new fetch mode.public java.lang.String toString()
toString in class java.lang.Objectprotected Response currentResponse()
protected void handleFirstResponse()
protected void throwOnCompleted()
protected void maybeContinue()
protected void onConnectionClosed()
protected int emitData(Response res)