This is an automated email from the ASF dual-hosted git repository. okram pushed a commit to branch tp4 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/tp4 by this push: new 6c60bcc Staging Comilation for the ability to be cached -- hashCode, equals... and ultimately clone. Need a way to deep clone functions as they can contain compilations. 6c60bcc is described below commit 6c60bcc7dc8ce2060b37051688845773a318f599 Author: Marko A. Rodriguez <okramma...@gmail.com> AuthorDate: Wed Mar 27 07:40:47 2019 -0600 Staging Comilation for the ability to be cached -- hashCode, equals... and ultimately clone. Need a way to deep clone functions as they can contain compilations. --- .../machine/bytecode/compiler/Compilation.java | 26 ++++++++++++++++++++++ .../tinkerpop/machine/species/LocalMachine.java | 12 +++++----- .../machine/species/remote/RemoteMachine.java | 8 +++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java index 5c02215..9b15d95 100644 --- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java +++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java @@ -129,6 +129,32 @@ public final class Compilation<C, S, E> implements Serializable { return this.functions.toString(); } // TODO: functions need access to compilations for nesting + + @Override + public int hashCode() { + return this.processorFactory.hashCode() ^ this.structureFactory.hashCode() ^ this.functions.hashCode(); + } + + @Override + public boolean equals(final Object object) { + return object instanceof Compilation && + this.functions.equals(((Compilation) object).functions) && + this.processorFactory.equals(((Compilation) object).processorFactory) && + this.structureFactory.equals(((Compilation) object).structureFactory); + } + + @Override + public Compilation<C, S, E> clone() { + try { + final Compilation<C, S, E> clone = (Compilation<C, S, E>) super.clone(); + clone.processor = null; + // clone.functions = ... we need to do a deep clone given the nested compilations + return clone; + } catch (final CloneNotSupportedException e) { + throw new RuntimeException(e.getMessage(), e); + } + } + //////// public static <C, S, E> Compilation<C, S, E> compile(final SourceCompilation<C> source, final Bytecode<C> bytecode) { diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/LocalMachine.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/LocalMachine.java index 79b958d..cf3e221 100644 --- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/LocalMachine.java +++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/LocalMachine.java @@ -73,13 +73,18 @@ public final class LocalMachine implements Machine { @Override public <C, E> Iterator<Traverser<C, E>> submit(Bytecode<C> bytecode) { bytecode = bytecode.clone(); - final UUID sourceId = LocalMachine.getSourceId(bytecode).orElse(UUID.randomUUID()); + final UUID sourceId = LocalMachine.getSourceId(bytecode).orElse(null); final SourceCompilation<C> source = (SourceCompilation<C>) this.sources.get(sourceId); return null == source ? Compilation.<C, Object, E>compile(bytecode).getProcessor() : Compilation.<C, Object, E>compile(source, bytecode).getProcessor(); } + @Override + public void close() { + this.sources.clear(); + } + public static Machine open() { return new LocalMachine(); } @@ -91,9 +96,4 @@ public final class LocalMachine implements Machine { } return Optional.empty(); } - - @Override - public void close() { - this.sources.clear(); - } } diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/remote/RemoteMachine.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/remote/RemoteMachine.java index 3eb5b89..98f39e5 100644 --- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/remote/RemoteMachine.java +++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/species/remote/RemoteMachine.java @@ -87,10 +87,6 @@ public final class RemoteMachine implements Machine, AutoCloseable { } } - public static Machine open(final int traverserServerPort, final String machineServerLocation, final int machineServerPort) { - return new RemoteMachine(traverserServerPort, machineServerLocation, machineServerPort); - } - @Override public void close() { try { @@ -102,6 +98,10 @@ public final class RemoteMachine implements Machine, AutoCloseable { } } + public static Machine open(final int traverserServerPort, final String machineServerLocation, final int machineServerPort) { + return new RemoteMachine(traverserServerPort, machineServerLocation, machineServerPort); + } + /** * @author Marko A. Rodriguez (http://markorodriguez.com) */