@Override public <E> CompletableFuture<RemoteTraversal<?, E>> submitAsync(final Bytecode bytecode) throws RemoteConnectionException { // default implementation for backward compatibility to 3.2.4 - this method will probably just become // the new submit() in 3.3.x when the deprecation is removed final CompletableFuture<RemoteTraversal<?, E>> promise = new CompletableFuture<>(); try { promise.complete(new EmbeddedRemoteTraversal(JavaTranslator.of(g).translate(bytecode))); } catch (Exception t) { promise.completeExceptionally(t); } return promise; }
public static <S extends TraversalSource, T extends Traversal.Admin<?, ?>> JavaTranslator<S, T> of(final S traversalSource) { return new JavaTranslator<>(traversalSource); }
private Object invokeMethod(final Object delegate, final Class<?> returnType, final String methodName, final Object... arguments) { if (methodCache.isEmpty()) buildMethodCache(delegate, methodCache); argumentsCopy[i] = translateObject(arguments[i]);
private Object translateObject(final Object object) { if (object instanceof Bytecode.Binding) return translateObject(((Bytecode.Binding) object).value()); else if (object instanceof Bytecode) { try { final Traversal.Admin<?, ?> traversal = (Traversal.Admin) this.anonymousTraversalStart.invoke(null); for (final Bytecode.Instruction instruction : ((Bytecode) object).getStepInstructions()) { invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments()); final Map<String, Object> map = new HashMap<>(); final Configuration configuration = ((TraversalStrategyProxy) object).getConfiguration(); configuration.getKeys().forEachRemaining(key -> map.put(key, translateObject(configuration.getProperty(key)))); return invokeStrategyCreationMethod(object, map); } else if (object instanceof Map) { final Map<Object, Object> map = object instanceof Tree ? new HashMap<>(((Map) object).size()); for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { map.put(translateObject(entry.getKey()), translateObject(entry.getValue())); final List<Object> list = new ArrayList<>(((List) object).size()); for (final Object o : (List) object) { list.add(translateObject(o)); final BulkSet<Object> bulkSet = new BulkSet<>(); for (final Map.Entry<?, Long> entry : ((BulkSet<?>) object).asBulk().entrySet()) { bulkSet.add(translateObject(entry.getKey()), entry.getValue()); new HashSet<>(((Set) object).size()); for (final Object o : (Set) object) {
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationShort() { return translator.translate(g.V().asAdmin().getBytecode()); }
private JavaTranslator(final S traversalSource) { this.traversalSource = traversalSource; this.anonymousTraversal = traversalSource.getAnonymousTraversalClass().orElse(null); this.anonymousTraversalStart = getStartMethodFromAnonymousTraversal(); }
@Override public T translate(final Bytecode bytecode) { TraversalSource dynamicSource = this.traversalSource; Traversal.Admin<?, ?> traversal = null; for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) { dynamicSource = (TraversalSource) invokeMethod(dynamicSource, TraversalSource.class, instruction.getOperator(), instruction.getArguments()); } boolean spawned = false; for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) { if (!spawned) { traversal = (Traversal.Admin) invokeMethod(dynamicSource, Traversal.class, instruction.getOperator(), instruction.getArguments()); spawned = true; } else invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments()); } return (T) traversal; }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationMedium() { return translator.translate(g.V().out().in("link").out().in("link").asAdmin().getBytecode()); }
private Object translateObject(final Object object) { if (object instanceof Bytecode.Binding) return translateObject(((Bytecode.Binding) object).value()); else if (object instanceof Bytecode) { try { final Traversal.Admin<?, ?> traversal = (Traversal.Admin) this.anonymousTraversalStart.invoke(null); for (final Bytecode.Instruction instruction : ((Bytecode) object).getStepInstructions()) { invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments()); final Map<String, Object> map = new HashMap<>(); final Configuration configuration = ((TraversalStrategyProxy) object).getConfiguration(); configuration.getKeys().forEachRemaining(key -> map.put(key, translateObject(configuration.getProperty(key)))); return invokeStrategyCreationMethod(object, map); } else if (object instanceof Map) { final Map<Object, Object> map = object instanceof Tree ? new HashMap<>(((Map) object).size()); for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) { map.put(translateObject(entry.getKey()), translateObject(entry.getValue())); final List<Object> list = new ArrayList<>(((List) object).size()); for (final Object o : (List) object) { list.add(translateObject(o)); final BulkSet<Object> bulkSet = new BulkSet<>(); for (final Map.Entry<?, Long> entry : ((BulkSet<?>) object).asBulk().entrySet()) { bulkSet.add(translateObject(entry.getKey()), entry.getValue()); new HashSet<>(((Set) object).size()); for (final Object o : (Set) object) {
private JavaTranslator(final S traversalSource) { this.traversalSource = traversalSource; this.anonymousTraversal = traversalSource.getAnonymousTraversalClass().orElse(null); this.anonymousTraversalStart = getStartMethodFromAnonymousTraversal(); }
@Override public T translate(final Bytecode bytecode) { TraversalSource dynamicSource = this.traversalSource; Traversal.Admin<?, ?> traversal = null; for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) { dynamicSource = (TraversalSource) invokeMethod(dynamicSource, TraversalSource.class, instruction.getOperator(), instruction.getArguments()); } boolean spawned = false; for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) { if (!spawned) { traversal = (Traversal.Admin) invokeMethod(dynamicSource, Traversal.class, instruction.getOperator(), instruction.getArguments()); spawned = true; } else invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments()); } return (T) traversal; }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationWithStrategy() { return translator.translate(g.withStrategies(ReadOnlyStrategy.instance()) .withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()) .V().out().in("link").out().in("link").asAdmin().getBytecode()); } }
private Object invokeMethod(final Object delegate, final Class<?> returnType, final String methodName, final Object... arguments) { if (methodCache.isEmpty()) buildMethodCache(delegate, methodCache); argumentsCopy[i] = translateObject(arguments[i]);
public static <S extends TraversalSource, T extends Traversal.Admin<?, ?>> JavaTranslator<S, T> of(final S traversalSource) { return new JavaTranslator<>(traversalSource); }
@Override public <E> CompletableFuture<RemoteTraversal<?, E>> submitAsync(final Bytecode bytecode) throws RemoteConnectionException { // default implementation for backward compatibility to 3.2.4 - this method will probably just become // the new submit() in 3.3.x when the deprecation is removed final CompletableFuture<RemoteTraversal<?, E>> promise = new CompletableFuture<>(); try { promise.complete(new EmbeddedRemoteTraversal(JavaTranslator.of(g).translate(bytecode))); } catch (Exception t) { promise.completeExceptionally(t); } return promise; }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationLong() { return translator.translate(g.V().match( as("a").has("song", "name", "HERE COMES SUNSHINE"), as("a").map(inE("followedBy").values("weight").mean()).as("b"), as("a").inE("followedBy").as("c"), as("c").filter(values("weight").where(P.gte("b"))).outV().as("d")). <String>select("d").by("name").asAdmin().getBytecode()); }