tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject tinkerpop git commit: Added a Gryo serializer for Bytecode. TINKERPOP-1464
Date Sat, 24 Sep 2016 18:04:51 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1464 [created] 66d206a09


Added a Gryo serializer for Bytecode. TINKERPOP-1464


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/66d206a0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/66d206a0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/66d206a0

Branch: refs/heads/TINKERPOP-1464
Commit: 66d206a098f3c68d7bfb174c50d927f1181c18ff
Parents: b8530f7
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Sat Sep 24 14:03:30 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Sat Sep 24 14:03:30 2016 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   2 +
 .../gremlin/process/traversal/Bytecode.java     |   2 -
 .../structure/io/gryo/EntrySerializer.java      |  43 -----
 .../structure/io/gryo/GryoClassResolver.java    |   3 +
 .../gremlin/structure/io/gryo/GryoMapper.java   |  35 +++-
 .../structure/io/gryo/GryoSerializers.java      | 178 +++++++++++++++++--
 .../structure/io/gryo/PairSerializer.java       |  45 -----
 .../structure/io/gryo/URISerializer.java        |  49 -----
 .../structure/io/gryo/UUIDSerializer.java       |  50 ------
 .../structure/io/gryo/UtilSerializers.java      | 140 +++++++++++++++
 10 files changed, 337 insertions(+), 210 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index a1b405f..a3e21a1 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -31,6 +31,8 @@ TinkerPop 3.2.3 (Release Date: NOT OFFICIALLY RELEASED YET)
 * Fixed a bug in serialization of `Lambda` instances in GraphSON, which prevented their use
in remote traversals.
 * Fixed a naming bug in Gremlin-Python where `P._and` and `P._or` should be `P.and_` and
`P.or_`. (*breaking*)
 * `where()` predicate-based steps now support `by()`-modulation.
+* Added Gryo serialization for `Bytecode`.
+* Moved utility-based serializers to `UtilSerializers` for Gryo - these classes were private
and hence this change is non-breaking.
 * `TraversalRing` returns a `null` if it does not contain traversals (previously `IdentityTraversal`).
 * Fixed a `JavaTranslator` bug where `Bytecode` instructions were being mutated during translation.
 * Added `Path` to Gremlin-Python with respective GraphSON 2.0 deserializer.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
index c200741..3737cef 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
@@ -191,8 +191,6 @@ public final class Bytecode implements Cloneable, Serializable {
         public int hashCode() {
             return this.operator.hashCode() + Arrays.hashCode(this.arguments);
         }
-
-
     }
 
     public static class Binding<V> implements Serializable {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/EntrySerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/EntrySerializer.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/EntrySerializer.java
deleted file mode 100644
index 00215e0..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/EntrySerializer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.structure.io.gryo;
-
-import org.apache.tinkerpop.shaded.kryo.Kryo;
-import org.apache.tinkerpop.shaded.kryo.Serializer;
-import org.apache.tinkerpop.shaded.kryo.io.Input;
-import org.apache.tinkerpop.shaded.kryo.io.Output;
-
-import java.util.AbstractMap;
-import java.util.Map;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-final class EntrySerializer extends Serializer<Map.Entry> {
-    @Override
-    public void write(final Kryo kryo, final Output output, final Map.Entry entry) {
-        kryo.writeClassAndObject(output, entry.getKey());
-        kryo.writeClassAndObject(output, entry.getValue());
-    }
-
-    @Override
-    public Map.Entry read(final Kryo kryo, final Input input, final Class<Map.Entry>
entryClass) {
-        return new AbstractMap.SimpleEntry(kryo.readClassAndObject(input), kryo.readClassAndObject(input));
-    }
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
index 5d51d22..53f4382 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoClassResolver.java
@@ -33,6 +33,7 @@ import org.apache.tinkerpop.gremlin.structure.util.reference.ReferencePath;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceProperty;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexProperty;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
 import org.apache.tinkerpop.shaded.kryo.ClassResolver;
 import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.KryoException;
@@ -105,6 +106,8 @@ public class GryoClassResolver implements ClassResolver {
             type = Property.class;
         else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz)
&& Path.class.isAssignableFrom(clazz))
             type = Path.class;
+        else if (Lambda.class.isAssignableFrom(clazz))
+            type = Lambda.class;
         else
             type = clazz;
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index add254e..0a7d277 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -26,7 +26,12 @@ import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraver
 import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
 import org.apache.tinkerpop.gremlin.process.traversal.Contains;
 import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.FoldStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroupCountStep;
@@ -47,10 +52,13 @@ import org.apache.tinkerpop.gremlin.process.traversal.traverser.LP_O_OB_S_SE_SL_
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.O_OB_S_SE_SL_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.O_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalMetrics;
 import org.apache.tinkerpop.gremlin.process.traversal.util.ImmutableMetrics;
 import org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics;
+import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation;
+import org.apache.tinkerpop.gremlin.structure.Column;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -74,6 +82,8 @@ import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphSerializer;
+import org.apache.tinkerpop.gremlin.util.function.HashSetSupplier;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
 import org.apache.tinkerpop.shaded.kryo.ClassResolver;
 import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.KryoSerializable;
@@ -177,7 +187,7 @@ public final class GryoMapper implements Mapper<Kryo> {
     @Override
     public Kryo createMapper() {
         final Kryo kryo = new Kryo(classResolver.get(), new MapReferenceResolver(), new DefaultStreamFactory());
-        kryo.addDefaultSerializer(Map.Entry.class, new EntrySerializer());
+        kryo.addDefaultSerializer(Map.Entry.class, new UtilSerializers.EntrySerializer());
         kryo.setRegistrationRequired(registrationRequired);
         kryo.setReferences(referenceTracking);
         for (TypeRegistration tr : typeRegistrations)
@@ -224,6 +234,8 @@ public final class GryoMapper implements Mapper<Kryo> {
             put("junk", "dummy");
         }};
 
+        private static final Class ARRAYS_AS_LIST = Arrays.asList("dummy").getClass();
+
         private static final Class LINKED_HASH_MAP_ENTRY_CLASS = m.entrySet().iterator().next().getClass();
 
         /**
@@ -257,6 +269,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(GryoTypeReg.of(String[].class, 32));
             add(GryoTypeReg.of(Object[].class, 33));
             add(GryoTypeReg.of(ArrayList.class, 10));
+            add(GryoTypeReg.of(ARRAYS_AS_LIST, 134, new UtilSerializers.ArraysAsListSerializer()));
             add(GryoTypeReg.of(BigInteger.class, 34));
             add(GryoTypeReg.of(BigDecimal.class, 35));
             add(GryoTypeReg.of(Calendar.class, 39));
@@ -294,8 +307,8 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(GryoTypeReg.of(TimeZone.class, 42));
             add(GryoTypeReg.of(TreeMap.class, 45));
             add(GryoTypeReg.of(TreeSet.class, 50));
-            add(GryoTypeReg.of(UUID.class, 17, new UUIDSerializer()));
-            add(GryoTypeReg.of(URI.class, 72, new URISerializer()));
+            add(GryoTypeReg.of(UUID.class, 17, new UtilSerializers.UUIDSerializer()));
+            add(GryoTypeReg.of(URI.class, 72, new UtilSerializers.URISerializer()));
             add(GryoTypeReg.of(VertexTerminator.class, 13));
             add(GryoTypeReg.of(AbstractMap.SimpleEntry.class, 120));
             add(GryoTypeReg.of(AbstractMap.SimpleImmutableEntry.class, 121));
@@ -322,9 +335,21 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(GryoTypeReg.of(O_OB_S_SE_SL_Traverser.class, 89));
             add(GryoTypeReg.of(LP_O_OB_S_SE_SL_Traverser.class, 90));
             add(GryoTypeReg.of(LP_O_OB_P_S_SE_SL_Traverser.class, 91));
-            add(GryoTypeReg.of(DefaultRemoteTraverser.class, 123, new GryoSerializers.DefaultRemoteTraverserSerializer()));
 // ***LAST ID***
+            add(GryoTypeReg.of(DefaultRemoteTraverser.class, 123, new GryoSerializers.DefaultRemoteTraverserSerializer()));
 
             add(GryoTypeReg.of(Bytecode.class, 122, new GryoSerializers.BytecodeSerializer()));
+            add(GryoTypeReg.of(P.class, 124, new GryoSerializers.PSerializer()));
+            add(GryoTypeReg.of(Lambda.class, 125, new GryoSerializers.LambdaSerializer()));
+            add(GryoTypeReg.of(Bytecode.Binding.class, 126, new GryoSerializers.BindingSerializer()));
+            add(GryoTypeReg.of(Order.class, 127));
+            add(GryoTypeReg.of(Scope.class, 128));
+            add(GryoTypeReg.of(AndP.class, 129, new GryoSerializers.AndPSerializer()));
+            add(GryoTypeReg.of(OrP.class, 130, new GryoSerializers.OrPSerializer()));
+            add(GryoTypeReg.of(VertexProperty.Cardinality.class, 131));
+            add(GryoTypeReg.of(Column.class, 132));
+            add(GryoTypeReg.of(Pop.class, 133));
+            add(GryoTypeReg.of(SackFunctions.Barrier.class, 135));
+            add(GryoTypeReg.of(HashSetSupplier.class, 136, new UtilSerializers.HashSetSupplierSerializer()));
// ***LAST ID***
 
             add(GryoTypeReg.of(TraverserSet.class, 58));
             add(GryoTypeReg.of(Tree.class, 61));
@@ -336,7 +361,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(GryoTypeReg.of(MapMemory.class, 73));
             add(GryoTypeReg.of(MapReduce.NullObject.class, 74));
             add(GryoTypeReg.of(AtomicLong.class, 79));
-            add(GryoTypeReg.of(Pair.class, 88, new PairSerializer()));
+            add(GryoTypeReg.of(Pair.class, 88, new UtilSerializers.PairSerializer()));
             add(GryoTypeReg.of(TraversalExplanation.class, 106, new JavaSerializer()));
 
             add(GryoTypeReg.of(Duration.class, 93, new JavaTimeSerializers.DurationSerializer()));

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
index 945af87..dbe85ca 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoSerializers.java
@@ -20,14 +20,16 @@ package org.apache.tinkerpop.gremlin.structure.io.gryo;
 
 import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser;
 import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Property;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion;
-import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONXModuleV2d0;
+import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONTokens;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
@@ -38,6 +40,12 @@ import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPath;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedProperty;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexProperty;
+import org.apache.tinkerpop.gremlin.util.function.Lambda;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 /**
  * Class used to serialize graph-based objects such as vertices, edges, properties, and paths.
These objects are
@@ -126,30 +134,168 @@ public final class GryoSerializers {
     }
 
     public final static class BytecodeSerializer implements SerializerShim<Bytecode>
{
-        private static final GraphSONMapper mapper = GraphSONMapper.build()
-                .version(GraphSONVersion.V2_0)
-                .addCustomModule(GraphSONXModuleV2d0.build().create(false))
-                .create();
-
         @Override
         public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final Bytecode bytecode) {
-            try {
-                output.writeString(mapper.createMapper().writeValueAsString(bytecode));
-            } catch (Exception ex) {
-                throw new RuntimeException(ex);
-            }
+            final List<Bytecode.Instruction> sourceInstructions = IteratorUtils.list(
+                    IteratorUtils.filter(bytecode.getSourceInstructions().iterator(),
+                            i -> !i.getOperator().equals("withStrategies") &&
!i.getOperator().equals("withComputer")));
+            writeInstructions(kryo, output, sourceInstructions);
+            final List<Bytecode.Instruction> stepInstructions = IteratorUtils.list(bytecode.getStepInstructions().iterator());
+            writeInstructions(kryo, output, stepInstructions);
         }
 
         @Override
         public <I extends InputShim> Bytecode read(final KryoShim<I, ?> kryo,
final I input, final Class<Bytecode> clazz) {
+            final Bytecode bytecode = new Bytecode();
+            final int sourceInstructionCount = input.readInt();
+            for (int ix = 0; ix < sourceInstructionCount; ix++) {
+                final String operator = input.readString();
+                final Object[] args = kryo.readObject(input, Object[].class);
+                bytecode.addSource(operator, args);
+            }
+
+            final int stepInstructionCount = input.readInt();
+            for (int ix = 0; ix < stepInstructionCount; ix++) {
+                final String operator = input.readString();
+                final Object[] args = kryo.readObject(input, Object[].class);
+                bytecode.addStep(operator, args);
+            }
+
+            return bytecode;
+        }
+
+        private static <O extends OutputShim> void writeInstructions(final KryoShim<?,
O> kryo, final O output,
+                                                                     final List<Bytecode.Instruction>
instructions) {
+            output.writeInt(instructions.size());
+            for (Bytecode.Instruction inst : instructions) {
+                output.writeString(inst.getOperator());
+                kryo.writeObject(output, inst.getArguments());
+            }
+        }
+    }
+
+    public final static class AndPSerializer implements SerializerShim<AndP> {
+
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final AndP p) {
+            final List predicates = new ArrayList(p.getPredicates());
+            kryo.writeObject(output, predicates);
+        }
+
+        @Override
+        public <I extends InputShim> AndP read(final KryoShim<I, ?> kryo, final
I input, final Class<AndP> clazz) {
+            final List<P> predicates = kryo.readObject(input, ArrayList.class);
+            return new AndP(predicates);
+        }
+    }
+
+    public final static class OrPSerializer implements SerializerShim<OrP> {
+
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final OrP p) {
+            final List predicates = new ArrayList(p.getPredicates());
+            kryo.writeObject(output, predicates);
+        }
+
+        @Override
+        public <I extends InputShim> OrP read(final KryoShim<I, ?> kryo, final
I input, final Class<OrP> clazz) {
+            final List<P> predicates = kryo.readObject(input, ArrayList.class);
+            return new OrP(predicates);
+        }
+    }
+
+    public final static class PSerializer implements SerializerShim<P> {
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final P p) {
+            output.writeString(p.getBiPredicate().toString());
+            if (p.getValue() instanceof Collection) {
+                output.writeByte((byte) 0);
+                final Collection coll = (Collection) p.getValue();
+                output.writeInt(coll.size());
+                coll.forEach(v -> kryo.writeClassAndObject(output, v));
+            } else {
+                output.writeByte((byte) 1);
+                kryo.writeClassAndObject(output, p.getValue());
+            }
+        }
+
+        @Override
+        public <I extends InputShim> P read(final KryoShim<I, ?> kryo, final
I input, final Class<P> clazz) {
+            final String predicate = input.readString();
+            final boolean isCollection = input.readByte() == (byte) 0;
+            final Object value;
+            if (isCollection) {
+                value = new ArrayList();
+                final int size = input.readInt();
+                for (int ix = 0; ix < size; ix++) {
+                    ((List) value).add(kryo.readClassAndObject(input));
+                }
+            } else {
+                value = kryo.readClassAndObject(input);
+            }
+
             try {
-                return mapper.createMapper().readValue(input.readString(), Bytecode.class);
-            } catch (Exception ex) {
-                throw new RuntimeException(ex);
+                if (value instanceof Collection) {
+                    if (predicate.equals("between"))
+                        return P.between(((List) value).get(0), ((List) value).get(1));
+                    else if (predicate.equals("inside"))
+                        return P.between(((List) value).get(0), ((List) value).get(1));
+                    else if (predicate.equals("outside"))
+                        return P.outside(((List) value).get(0), ((List) value).get(1));
+                    else if (predicate.equals("within"))
+                        return P.within((Collection) value);
+                    else if (predicate.equals("without"))
+                        return P.without((Collection) value);
+                    else
+                        return (P) P.class.getMethod(predicate, Collection.class).invoke(null,
(Collection) value);
+                } else
+                    return (P) P.class.getMethod(predicate, Object.class).invoke(null, value);
+            } catch (final Exception e) {
+                throw new IllegalStateException(e.getMessage(), e);
             }
         }
     }
 
+    public final static class LambdaSerializer implements SerializerShim<Lambda> {
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final Lambda lambda) {
+            output.writeString(lambda.getLambdaScript());
+            output.writeString(lambda.getLambdaLanguage());
+            output.writeInt(lambda.getLambdaArguments());
+        }
+
+        @Override
+        public <I extends InputShim> Lambda read(final KryoShim<I, ?> kryo, final
I input, final Class<Lambda> clazz) {
+            final String script = input.readString();
+            final String language = input.readString();
+            final int arguments = input.readInt();
+            //
+            if (-1 == arguments || arguments > 2)
+                return new Lambda.UnknownArgLambda(script, language, arguments);
+            else if (0 == arguments)
+                return new Lambda.ZeroArgLambda<>(script, language);
+            else if (1 == arguments)
+                return new Lambda.OneArgLambda<>(script, language);
+            else
+                return new Lambda.TwoArgLambda<>(script, language);
+        }
+    }
+
+    public final static class BindingSerializer implements SerializerShim<Bytecode.Binding>
{
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final Bytecode.Binding binding) {
+            output.writeString(binding.variable());
+            kryo.writeClassAndObject(output, binding.value());
+        }
+
+        @Override
+        public <I extends InputShim> Bytecode.Binding read(final KryoShim<I, ?>
kryo, final I input, final Class<Bytecode.Binding> clazz) {
+            final String var = input.readString();
+            final Object val = kryo.readClassAndObject(input);
+            return new Bytecode.Binding(var, val);
+        }
+    }
+
     public final static class DefaultRemoteTraverserSerializer implements SerializerShim<DefaultRemoteTraverser>
{
         @Override
         public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final DefaultRemoteTraverser remoteTraverser) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/PairSerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/PairSerializer.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/PairSerializer.java
deleted file mode 100644
index 1465b24..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/PairSerializer.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.structure.io.gryo;
-
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.SerializerShim;
-import org.apache.tinkerpop.shaded.kryo.Kryo;
-import org.apache.tinkerpop.shaded.kryo.Serializer;
-import org.apache.tinkerpop.shaded.kryo.io.Input;
-import org.apache.tinkerpop.shaded.kryo.io.Output;
-import org.javatuples.Pair;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- */
-final class PairSerializer implements SerializerShim<Pair> {
-    @Override
-    public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final Pair pair) {
-        kryo.writeClassAndObject(output, pair.getValue0());
-        kryo.writeClassAndObject(output, pair.getValue1());
-    }
-
-    @Override
-    public <I extends InputShim> Pair read(final KryoShim<I, ?> kryo, final I
input, final Class<Pair> pairClass) {
-        return Pair.with(kryo.readClassAndObject(input), kryo.readClassAndObject(input));
-    }
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/URISerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/URISerializer.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/URISerializer.java
deleted file mode 100644
index a65bcea..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/URISerializer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.structure.io.gryo;
-
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.SerializerShim;
-
-import java.net.URI;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-final class URISerializer implements SerializerShim<URI> {
-
-    public URISerializer() { }
-
-    @Override
-    public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final URI uri) {
-        output.writeString(uri.toString());
-    }
-
-    @Override
-    public <I extends InputShim> URI read(final KryoShim<I, ?> kryo, final I
input, final Class<URI> uriClass) {
-        return URI.create(input.readString());
-    }
-
-    @Override
-    public boolean isImmutable() {
-        return true;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UUIDSerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UUIDSerializer.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UUIDSerializer.java
deleted file mode 100644
index d1d59d3..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UUIDSerializer.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.structure.io.gryo;
-
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
-import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.SerializerShim;
-
-import java.util.UUID;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-final class UUIDSerializer implements SerializerShim<UUID> {
-
-    public UUIDSerializer() { }
-
-    @Override
-    public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final UUID uuid) {
-        output.writeLong(uuid.getMostSignificantBits());
-        output.writeLong(uuid.getLeastSignificantBits());
-    }
-
-    @Override
-    public <I extends InputShim> UUID read(final KryoShim<I, ?> kryo, final I
input, final Class<UUID> uuidClass) {
-        return new UUID(input.readLong(), input.readLong());
-    }
-
-    @Override
-    public boolean isImmutable() {
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/66d206a0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UtilSerializers.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UtilSerializers.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UtilSerializers.java
new file mode 100644
index 0000000..6f0a632
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/UtilSerializers.java
@@ -0,0 +1,140 @@
+/*
+ * 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.structure.io.gryo;
+
+import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.SerializerShim;
+import org.apache.tinkerpop.gremlin.util.function.HashSetSupplier;
+import org.apache.tinkerpop.shaded.kryo.Kryo;
+import org.apache.tinkerpop.shaded.kryo.Serializer;
+import org.apache.tinkerpop.shaded.kryo.io.Input;
+import org.apache.tinkerpop.shaded.kryo.io.Output;
+import org.javatuples.Pair;
+
+import java.net.URI;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+final class UtilSerializers {
+
+    private UtilSerializers() {}
+
+    /**
+     * Serializer for {@code List} instances produced by {@code Arrays.asList()}.
+     */
+    public final static class ArraysAsListSerializer implements SerializerShim<List>
{
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final List list) {
+            final List l = new ArrayList(list);
+            kryo.writeObject(output, l);
+        }
+
+        @Override
+        public <I extends InputShim> List read(final KryoShim<I, ?> kryo, final
I input, final Class<List> clazz) {
+            return kryo.readObject(input, ArrayList.class);
+        }
+    }
+
+    public final static class HashSetSupplierSerializer implements SerializerShim<HashSetSupplier>
{
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final HashSetSupplier hashSetSupplier) {
+        }
+
+        @Override
+        public <I extends InputShim> HashSetSupplier read(final KryoShim<I, ?>
kryo, final I input, final Class<HashSetSupplier> clazz) {
+            return HashSetSupplier.instance();
+        }
+    }
+
+    static final class UUIDSerializer implements SerializerShim<UUID> {
+
+        public UUIDSerializer() { }
+
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final UUID uuid) {
+            output.writeLong(uuid.getMostSignificantBits());
+            output.writeLong(uuid.getLeastSignificantBits());
+        }
+
+        @Override
+        public <I extends InputShim> UUID read(final KryoShim<I, ?> kryo, final
I input, final Class<UUID> uuidClass) {
+            return new UUID(input.readLong(), input.readLong());
+        }
+
+        @Override
+        public boolean isImmutable() {
+            return true;
+        }
+    }
+
+    static final class URISerializer implements SerializerShim<URI> {
+
+        public URISerializer() { }
+
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final URI uri) {
+            output.writeString(uri.toString());
+        }
+
+        @Override
+        public <I extends InputShim> URI read(final KryoShim<I, ?> kryo, final
I input, final Class<URI> uriClass) {
+            return URI.create(input.readString());
+        }
+
+        @Override
+        public boolean isImmutable() {
+            return true;
+        }
+    }
+
+    static final class PairSerializer implements SerializerShim<Pair> {
+        @Override
+        public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final
O output, final Pair pair) {
+            kryo.writeClassAndObject(output, pair.getValue0());
+            kryo.writeClassAndObject(output, pair.getValue1());
+        }
+
+        @Override
+        public <I extends InputShim> Pair read(final KryoShim<I, ?> kryo, final
I input, final Class<Pair> pairClass) {
+            return Pair.with(kryo.readClassAndObject(input), kryo.readClassAndObject(input));
+        }
+    }
+
+    static final class EntrySerializer extends Serializer<Map.Entry> {
+        @Override
+        public void write(final Kryo kryo, final Output output, final Map.Entry entry) {
+            kryo.writeClassAndObject(output, entry.getKey());
+            kryo.writeClassAndObject(output, entry.getValue());
+        }
+
+        @Override
+        public Map.Entry read(final Kryo kryo, final Input input, final Class<Map.Entry>
entryClass) {
+            return new AbstractMap.SimpleEntry(kryo.readClassAndObject(input), kryo.readClassAndObject(input));
+        }
+    }
+}


Mime
View raw message