org.apache.tinkerpop.gremlin.driver.ResultQueue Maven / Gradle / Ivy
/*
* 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.driver.message.ResponseMessage;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
import org.javatuples.Pair;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicReference;
/**
* A queue of incoming {@link Result} objects. The queue is updated by the {@link Handler.GremlinResponseHandler}
* until a response terminator is identified.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
final class ResultQueue {
private final LinkedBlockingQueue resultLinkedBlockingQueue;
private Object aggregatedResult = null;
private final AtomicReference error = new AtomicReference<>();
private final CompletableFuture readComplete;
private final Queue>,Integer>> waiting = new ConcurrentLinkedQueue<>();
private Map statusAttributes = null;
public ResultQueue(final LinkedBlockingQueue resultLinkedBlockingQueue, final CompletableFuture readComplete) {
this.resultLinkedBlockingQueue = resultLinkedBlockingQueue;
this.readComplete = readComplete;
}
/**
* Adds a {@link Result} to the queue which will be later read by the {@link ResultSet}.
*
* @param result a return value from the {@link Traversal} or script submitted for execution
*/
public void add(final Result result) {
this.resultLinkedBlockingQueue.offer(result);
tryDrainNextWaiting(false);
}
/**
* Adds a side-effect to the queue which may later be read by the {@link ResultSet}. Note that the side-effect
* is only returned when a {@link Traversal} is submitted and refers to the side-effects defined in that traversal.
* A "script" will not return side-effects.
*
* @param aggregateTo the value of the {@link ResponseMessage} metadata for {@link Tokens#ARGS_AGGREGATE_TO}.
* @param sideEffectValue the value of the side-effect itself
* @deprecated As of release 3.3.8, not directly replaced in the protocol as side-effect retrieval after
* traversal iteration is not being promoted anymore as a feature.
*/
@Deprecated
public void addSideEffect(final String aggregateTo, final Object sideEffectValue) {
switch (aggregateTo) {
case Tokens.VAL_AGGREGATE_TO_BULKSET:
if (!(sideEffectValue instanceof Traverser.Admin))
throw new IllegalStateException(String.format("Side-effect value %s is a %s which does not aggregate to %s",
sideEffectValue, sideEffectValue.getClass().getSimpleName(), aggregateTo));
if (null == aggregatedResult) aggregatedResult = new BulkSet();
final BulkSet
© 2015 - 2025 Weber Informatics LLC | Privacy Policy