Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.tinkerpop.gremlin.groovy.engine;
import com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
import com.tinkerpop.gremlin.groovy.plugin.GremlinPlugin;
import com.tinkerpop.gremlin.structure.Graph;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.javatuples.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.script.Bindings;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
* Execute Gremlin scripts against a {@code ScriptEngine} instance. It is designed to host any JSR-223 enabled
* {@code ScriptEngine} and assumes such engines are designed to be thread-safe in the evaluation. Script evaluation
* functions return a {@link CompletableFuture} where scripts may timeout if their evaluation
* takes too long. The default timeout is 8000ms.
*
* By default, the {@code GremlinExecutor} initializes itself to use a shared thread pool initialized with four
* threads. This default thread pool is shared for both the task of executing script evaluations and for scheduling
* timeouts. It is worth noting that a timeout simply triggers the returned {@link CompletableFuture} to abort, but
* the thread processing the script will continue to evaluate until completion. This offers only marginal protection
* against run-away scripts.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class GremlinExecutor implements AutoCloseable {
private static final Logger logger = LoggerFactory.getLogger(GremlinExecutor.class);
/**
* {@link ScriptEngines} instance to evaluate Gremlin script requests.
*/
private ScriptEngines scriptEngines;
private final Map settings;
private final long scriptEvaluationTimeout;
private final Bindings globalBindings;
private final List> use;
private final ExecutorService executorService;
private final ScheduledExecutorService scheduledExecutorService;
private final Consumer beforeEval;
private final Consumer afterSuccess;
private final Consumer afterTimeout;
private final BiConsumer afterFailure;
private final Set enabledPlugins;
private GremlinExecutor(final Map settings, final List> use,
final long scriptEvaluationTimeout, final Bindings globalBindings,
final ExecutorService executorService, final ScheduledExecutorService scheduledExecutorService,
final Consumer beforeEval, final Consumer afterSuccess,
final Consumer afterTimeout, final BiConsumer afterFailure,
final Set enabledPlugins) {
this.executorService = executorService;
this.scheduledExecutorService = scheduledExecutorService;
this.beforeEval = beforeEval;
this.afterSuccess = afterSuccess;
this.afterTimeout = afterTimeout;
this.afterFailure = afterFailure;
this.use = use;
this.settings = settings;
this.scriptEvaluationTimeout = scriptEvaluationTimeout;
this.globalBindings = globalBindings;
this.enabledPlugins = enabledPlugins;
this.scriptEngines = createScriptEngines();
}
public CompletableFuture