You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/04/23 15:13:57 UTC

[1/2] incubator-tinkerpop git commit: Added some comments as a reminder why Map creation was important to the serializers.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/refactor-io [created] 30d0388c1


Added some comments as a reminder why Map creation was important to the serializers.


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

Branch: refs/heads/refactor-io
Commit: 03e07c9b8314171f71b2b06c2510bb2dbd625f6f
Parents: f462308
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 23 06:44:55 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 23 06:44:55 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/io/graphson/GraphSONModule.java         | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/03e07c9b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index ec620ea..d6ae7c0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -81,6 +81,7 @@ public class GraphSONModule extends SimpleModule {
         }
 
         private static void ser(final VertexProperty property, final JsonGenerator jsonGenerator) throws IOException {
+            // creation of the map enables all the fields to be properly written with their type if required
             final Map<String, Object> m = new HashMap<>();
             m.put(GraphSONTokens.ID, property.id());
             m.put(GraphSONTokens.VALUE, property.value());
@@ -123,6 +124,7 @@ public class GraphSONModule extends SimpleModule {
         }
 
         private static void ser(final Property property, final JsonGenerator jsonGenerator) throws IOException {
+            // creation of the map enables all the fields to be properly written with their type if required
             final Map<String, Object> m = new HashMap<>();
             m.put(GraphSONTokens.VALUE, property.value());
             jsonGenerator.writeObject(m);
@@ -148,6 +150,7 @@ public class GraphSONModule extends SimpleModule {
         }
 
         private static void ser(final Edge edge, final JsonGenerator jsonGenerator) throws IOException {
+            // creation of the map enables all the fields to be properly written with their type if required
             final Map<String, Object> m = new HashMap<>();
             m.put(GraphSONTokens.ID, edge.id());
             m.put(GraphSONTokens.LABEL, edge.label());
@@ -189,6 +192,7 @@ public class GraphSONModule extends SimpleModule {
 
         private static void ser(final Vertex vertex, final JsonGenerator jsonGenerator)
                 throws IOException {
+            // creation of the map enables all the fields to be properly written with their type if required
             final Map<String, Object> m = new HashMap<>();
             m.put(GraphSONTokens.ID, vertex.id());
             m.put(GraphSONTokens.LABEL, vertex.label());
@@ -224,6 +228,7 @@ public class GraphSONModule extends SimpleModule {
 
         private static void ser(final Path path, final JsonGenerator jsonGenerator)
                 throws IOException {
+            // creation of the map enables all the fields to be properly written with their type if required
             final Map<String, Object> m = new HashMap<>();
             m.put(GraphSONTokens.LABELS, path.labels());
             m.put(GraphSONTokens.OBJECTS, path.objects());
@@ -250,8 +255,8 @@ public class GraphSONModule extends SimpleModule {
         }
 
         private static void serializeInternal(final TraversalMetrics traversalMetrics, final JsonGenerator jsonGenerator) throws IOException {
+            // creation of the map enables all the fields to be properly written with their type if required
             final Map<String, Object> m = new HashMap<>();
-
             m.put(GraphSONTokens.DURATION, traversalMetrics.getDuration(TimeUnit.NANOSECONDS) / 1000000d);
             List<Map<String, Object>> metrics = new ArrayList<>();
             traversalMetrics.getMetrics().forEach(it -> metrics.add(metricsToMap(it)));


[2/2] incubator-tinkerpop git commit: Make the StarGraphSerializer take Direction for edges.

Posted by sp...@apache.org.
Make the StarGraphSerializer take Direction for edges.


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

Branch: refs/heads/refactor-io
Commit: 30d0388c19d724e5f0b6f204134bcf3a63171cd1
Parents: 03e07c9
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 23 09:13:23 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 23 09:13:23 2015 -0400

----------------------------------------------------------------------
 .../gremlin/structure/io/gryo/GryoMapper.java   |  2 +-
 .../util/star/StarGraphSerializer.java          | 38 ++++++++++++++------
 2 files changed, 28 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/30d0388c/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 e0a18cd..a5db767 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
@@ -198,7 +198,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferenceVertex.class, null, 84));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferencePath.class, null, 85));
 
-            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(StarGraph.class, kryo -> StarGraphSerializer.instance(), 86)); // ***LAST ID**
+            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(StarGraph.class, kryo -> StarGraphSerializer.with(Direction.BOTH), 86)); // ***LAST ID**
 
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Edge.class, kryo -> new GraphSerializer.EdgeSerializer(), 65));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Vertex.class, kryo -> new GraphSerializer.VertexSerializer(), 66));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/30d0388c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
index e9caeed..f038fd9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
@@ -36,13 +36,31 @@ import java.util.Map;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public final class StarGraphSerializer extends Serializer<StarGraph> {
 
-    private static StarGraphSerializer INSTANCE = new StarGraphSerializer();
+    private static final Map<Direction,StarGraphSerializer> CACHE = new HashMap<>();
 
-    private StarGraphSerializer() {
+    private final Direction edgeDirectionToSerialize;
 
+    static {
+        CACHE.put(Direction.BOTH, new StarGraphSerializer(Direction.BOTH));
+        CACHE.put(Direction.IN, new StarGraphSerializer(Direction.IN));
+        CACHE.put(Direction.OUT, new StarGraphSerializer(Direction.OUT));
+        CACHE.put(null, new StarGraphSerializer(null));
+    }
+
+    private StarGraphSerializer(final Direction edgeDirectionToSerialize) {
+        this.edgeDirectionToSerialize = edgeDirectionToSerialize;
+    }
+
+    /**
+     * Gets a serializer from the cache.  Use {@code null} for the direction when requiring a serializer that
+     * doesn't serialize the edges of a vertex.
+     */
+    public static StarGraphSerializer with(final Direction direction) {
+        return CACHE.get(direction);
     }
 
     @Override
@@ -92,11 +110,13 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
         return starGraph;
     }
 
-    //////
-
-    private static void writeEdges(final Kryo kryo, final Output output, final Map<String, List<Edge>> starEdges, final Direction direction) {
-        kryo.writeObject(output, null != starEdges);
-        if (null != starEdges) {
+    private void writeEdges(final Kryo kryo, final Output output, final Map<String, List<Edge>> starEdges, final Direction direction) {
+        // only write edges if there are some AND if the user requested them to be serialized AND if they match
+        // the direction being serialized by the format
+        final boolean writeEdges = null != starEdges && edgeDirectionToSerialize != null
+                && (edgeDirectionToSerialize == direction || edgeDirectionToSerialize == Direction.BOTH);
+        kryo.writeObject(output, writeEdges);
+        if (writeEdges) {
             kryo.writeObject(output, starEdges.size());
             for (final Map.Entry<String, List<Edge>> edges : starEdges.entrySet()) {
                 kryo.writeObject(output, edges.getKey());
@@ -126,8 +146,4 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
             }
         }
     }
-
-    public static StarGraphSerializer instance() {
-        return INSTANCE;
-    }
 }