org.apache.tinkerpop.gremlin.driver.ResultSet Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.tinkerpop.gremlin.driver;
import org.apache.tinkerpop.gremlin.util.message.RequestMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* A {@code 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 {@code ResultSet} and
* therefore may not be available immediately. As such, {@code 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 an {@link Result} which can be used to retrieve the item once it is on the client side.
*
* Note that a {@code 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 {@link #one()} followed
* by {@link #all()} will make it so that the {@link List} of results returned from {@link #all()} have one
* {@link Result} missing from the total set as it was already retrieved by {@link #one}.
*
* This class is not thread-safe.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public final class ResultSet implements Iterable {
private final ResultQueue resultQueue;
private final ExecutorService executor;
private final RequestMessage originalRequestMessage;
private final Host host;
private final CompletableFuture readCompleted;
public ResultSet(final ResultQueue resultQueue, final ExecutorService executor,
final CompletableFuture readCompleted, final RequestMessage originalRequestMessage,
final Host host) {
this.executor = executor;
this.host = host;
this.resultQueue = resultQueue;
this.readCompleted = readCompleted;
this.originalRequestMessage = originalRequestMessage;
}
public RequestMessage getOriginalRequestMessage() {
return originalRequestMessage;
}
public Host getHost() {
return host;
}
/**
* Returns a future that will complete when {@link #allItemsAvailable()} is {@code true} and will contain the
* attributes from the response.
*/
public CompletableFuture
© 2015 - 2025 Weber Informatics LLC | Privacy Policy