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:58 UTC
[2/2] incubator-tinkerpop git commit: Make the StarGraphSerializer
take Direction for edges.
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;
- }
}