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/07/31 19:20:54 UTC

[03/10] incubator-tinkerpop git commit: Mapper.Builder now supports the addition of multiple IoRegistry objects.

Mapper.Builder now supports the addition of multiple IoRegistry objects.

This allows the user to easily add IoRegistry instances from multiple Graph implementations.  This is of course useful for data migrations where each graph has its own IoRegistry.


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

Branch: refs/heads/master
Commit: d33fb15fd5d70e90b81edf16aba489b8eb8f7730
Parents: 31aeb13
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 28 12:57:58 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 28 12:57:58 2015 -0400

----------------------------------------------------------------------
 docs/src/gremlin-applications.asciidoc          |  3 +
 .../tinkerpop/gremlin/structure/io/Mapper.java  |  6 +-
 .../structure/io/graphson/GraphSONIo.java       |  3 +-
 .../structure/io/graphson/GraphSONMapper.java   |  8 +--
 .../gremlin/structure/io/gryo/GryoIo.java       |  2 +-
 .../gremlin/structure/io/gryo/GryoMapper.java   |  9 +--
 .../gremlin/structure/io/gryo/GryoPool.java     | 55 +++++++++------
 .../tinkerpop/gremlin/structure/io/IoX.java     | 50 ++++++++++++++
 .../gremlin/structure/io/IoXIoRegistry.java     | 44 ++++++++++++
 .../tinkerpop/gremlin/structure/io/IoY.java     | 52 +++++++++++++++
 .../gremlin/structure/io/IoYIoRegistry.java     | 44 ++++++++++++
 .../structure/io/gryo/GryoMapperTest.java       | 70 +++++++++++++++++++-
 .../gremlin/structure/io/gryo/GryoPoolTest.java | 68 ++++++-------------
 .../driver/ser/GryoMessageSerializerV1d0.java   | 57 ++++++++++++----
 14 files changed, 376 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index e38af95..2949957 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -740,9 +740,12 @@ It has the MIME type of `application/vnd.gremlin-v1.0+gryo` and the following co
 |Key |Description |Default
 |serializeResultToString |When set to `true`, results are serialized by first calling `toString()` on each object in the result list resulting in an extended MIME Type of `application/vnd.gremlin-v1.0+gryo-stringd`.  When set to `false` Kryo-based serialization is applied. |_false_
 |useMapperFromGraph |Specifies the name of the `Graph` (from the `graphs` `Map` in the configuration file) from which to plugin any custom serializers that are tied to it. |_none_
+|ioRegistries |A list of `IoRegistry` implementations to be applied to the serializer.
 |custom |A list of classes with custom kryo `Serializer` implementations related to them in the form of `<class>;<serializer-class>`. |_none_
 |=========================================================
 
+As described above, there are multiple ways in which to register serializers for Kryo-based serialization.  These configurations can be used in conjunction with one another where there is a specific ordering to how the configurations are applied.  The `userMapperFromGraph` setting is applied first, followed by any `ioRegistries` and finalized by the `custom` setting.
+
 Best Practices
 ~~~~~~~~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
index 16f7a9a..4aeb3b7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
@@ -40,7 +40,11 @@ public interface Mapper<T> {
         /**
          * Adds a vendor supplied {@link IoRegistry} to the {@code Mapper.Builder} which enables it to check for
          * vendor custom serializers to add to the {@link Mapper}.  All {@link Io} implementations should expose
-         * this method via this {@link Builder} so that it is compatible with {@link Graph#io}.
+         * this method via this {@link Builder} so that it is compatible with {@link Graph#io}. Successive calls
+         * to this method will add multiple registries.  Registry order must be respected when doing so.  In
+         * other words, data written with {@link IoRegistry} {@code A} added first and {@code B} second must be read
+         * by a {@code Mapper} with that same registry ordering.  Attempting to add {@code B} before {@code A} will
+         * result in errors.
          */
         public B addRegistry(final IoRegistry registry);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
index 29d14cf..f4044e1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.structure.io.graphson;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.io.Io;
 import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper;
 
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -64,7 +65,7 @@ public final class GraphSONIo implements Io<GraphSONReader.Builder, GraphSONWrit
      */
     @Override
     public GraphSONMapper.Builder mapper() {
-        return GraphSONMapper.build().addRegistry(this.registry);
+        return (null == this.registry) ? GraphSONMapper.build() : GraphSONMapper.build().addRegistry(registry);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
index ea1ea2b..0e5eb5b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
@@ -117,7 +117,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
         private boolean loadCustomModules = false;
         private boolean normalize = false;
         private boolean embedTypes = false;
-        private IoRegistry registry = null;
+        private List<IoRegistry> registries = new ArrayList<>();
         private GraphSONVersion version = GraphSONVersion.V1_0;
 
         private Builder() {
@@ -128,7 +128,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
          */
         @Override
         public Builder addRegistry(final IoRegistry registry) {
-            this.registry = registry;
+            registries.add(registry);
             return this;
         }
 
@@ -182,10 +182,10 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
         }
 
         public GraphSONMapper create() {
-            if (registry != null) {
+            registries.forEach(registry -> {
                 final List<Pair<Class, SimpleModule>> simpleModules = registry.find(GraphSONIo.class, SimpleModule.class);
                 simpleModules.stream().map(Pair::getValue1).forEach(this.customModules::add);
-            }
+            });
 
             return new GraphSONMapper(customModules, loadCustomModules, normalize, embedTypes, version);
         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
index bc4b6aa..aca9d74 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
@@ -64,7 +64,7 @@ public final class GryoIo implements Io<GryoReader.Builder, GryoWriter.Builder,
      */
     @Override
     public GryoMapper.Builder mapper() {
-        return GryoMapper.build().addRegistry(this.registry);
+        return (null == this.registry) ? GryoMapper.build() : GryoMapper.build().addRegistry(this.registry);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/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 8d88f93..8b96052 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
@@ -248,7 +248,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(DependantMutableMetrics.class, null, 80));
         }};
 
-        private IoRegistry registry = null;
+        private List<IoRegistry> registries = new ArrayList<>();
 
         /**
          * Starts numbering classes for Gryo serialization at 65536 to leave room for future usage by TinkerPop.
@@ -263,7 +263,8 @@ public final class GryoMapper implements Mapper<Kryo> {
          */
         @Override
         public Builder addRegistry(final IoRegistry registry) {
-            this.registry = registry;
+            if (null == registry) throw new IllegalArgumentException("The registry cannot be null");
+            this.registries.add(registry);
             return this;
         }
 
@@ -299,7 +300,7 @@ public final class GryoMapper implements Mapper<Kryo> {
          */
         public GryoMapper create() {
             // consult the registry if provided and inject registry entries as custom classes.
-            if (registry != null) {
+            registries.forEach(registry-> {
                 final List<Pair<Class, Object>> serializers = registry.find(GryoIo.class);
                 serializers.forEach(p -> {
                     if (null == p.getValue1())
@@ -315,7 +316,7 @@ public final class GryoMapper implements Mapper<Kryo> {
                                 Serializer.class.getName(), Kryo.class.getSimpleName(),
                                 Serializer.class.getSimpleName()));
                 });
-            }
+            });
 
             return new GryoMapper(serializationList);
         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
index d27694e..426997e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
@@ -22,7 +22,9 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
 
 import java.lang.reflect.Method;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Queue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.function.Consumer;
@@ -47,11 +49,14 @@ public final class GryoPool {
 
     /**
      * Create a pool of readers and writers from a {@code Configuration} object.  There are two configuration keys
-     * expected: "gremlin.io.registry" which defines a fully qualified class name of an {@link IoRegistry}
-     * implementation and the "gremlin.io.gryo.poolSize" which defines the initial size of the {@code GryoPool}.
+     * expected: "gremlin.io.registry" which defines comma separated list of the fully qualified class names of
+     * {@link IoRegistry} implementations to use and the "gremlin.io.gryo.poolSize" which defines the initial size
+     * of the {@code GryoPool}.  As with usage of {@link GryoMapper.Builder#addRegistry(IoRegistry)}, the order in
+     * which these items are added matters greatly.  The order used for writing should be the order used for reading.
      */
     public GryoPool(final Configuration conf) {
-        this(conf.getInt(CONFIG_IO_GRYO_POOL_SIZE, 256), Type.READER_WRITER, tryCreateIoRegistry(conf.getString(CONFIG_IO_REGISTRY, "")));
+        this(conf.getInt(CONFIG_IO_GRYO_POOL_SIZE, 256), Type.READER_WRITER,
+                tryCreateIoRegistry(conf.getList(CONFIG_IO_REGISTRY, Collections.emptyList())));
     }
 
     /**
@@ -61,7 +66,7 @@ public final class GryoPool {
      * @param poolSize initial size of the pool.
      */
     public GryoPool(final int poolSize) {
-        this(poolSize, Type.READER_WRITER, Optional.empty());
+        this(poolSize, Type.READER_WRITER, Collections.emptyList());
     }
 
     /**
@@ -70,11 +75,11 @@ public final class GryoPool {
      *
      * @param poolSize initial size of the pool.
      * @param type the type of pool.
-     * @param ioRegistry the registry to assign to each {@link GryoReader} and {@link GryoWriter} instances.
+     * @param registries a list of registries to assign to each {@link GryoReader} and {@link GryoWriter} instances.
      */
-    public GryoPool(final int poolSize, final Type type, final Optional<IoRegistry> ioRegistry) {
+    public GryoPool(final int poolSize, final Type type, final List<IoRegistry> registries) {
         final GryoMapper.Builder mapperBuilder = GryoMapper.build();
-        ioRegistry.ifPresent(mapperBuilder::addRegistry);
+        registries.forEach(mapperBuilder::addRegistry);
 
         // should be able to re-use the GryoMapper - it creates fresh kryo instances from its createMapper method
         mapper = mapperBuilder.create();
@@ -123,22 +128,28 @@ public final class GryoPool {
         this.offerWriter(gryoWriter);
     }
 
-    private static Optional<IoRegistry> tryCreateIoRegistry(final String className) {
-        if (className.isEmpty()) return Optional.empty();
+    private static List<IoRegistry> tryCreateIoRegistry(final List<Object> classNames) {
+        if (classNames.isEmpty()) return Collections.emptyList();
 
-        try {
-            final Class<?> clazz = Class.forName(className);
+        final List<IoRegistry> registries = new ArrayList<>();
+        classNames.forEach(c -> {
             try {
-                final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
-                if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
-                    return Optional.of((IoRegistry) instanceMethod.invoke(null));
-                else
-                    throw new Exception();
-            } catch (Exception methodex) {
-                return Optional.of((IoRegistry) clazz.newInstance());
+                final String className = c.toString();
+                final Class<?> clazz = Class.forName(className);
+                try {
+                    final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
+                    if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
+                        registries.add((IoRegistry) instanceMethod.invoke(null));
+                    else
+                        throw new Exception();
+                } catch (Exception methodex) {
+                    // tried getInstance() and that failed so try newInstance() no-arg constructor
+                    registries.add((IoRegistry) clazz.newInstance());
+                }
+            } catch (Exception ex) {
+                throw new IllegalStateException(ex);
             }
-        } catch (Exception ex) {
-            throw new IllegalStateException(ex);
-        }
+        });
+        return registries;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java
new file mode 100644
index 0000000..2f67382
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+/**
+ * A test class to be serialized.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoX {
+    private String x;
+
+    private IoX() {}
+
+    public IoX(final String x) {
+        this.x = x;
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final IoX ioX = (IoX) o;
+
+        return x.equals(ioX.x);
+
+    }
+
+    @Override
+    public int hashCode() {
+        return x.hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
new file mode 100644
index 0000000..dabdae8
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoXIoRegistry {
+    public static class ConstructorBased extends AbstractIoRegistry {
+        public ConstructorBased() {
+            register(GryoIo.class, IoX.class, null);
+        }
+    }
+
+    public static class InstanceBased extends AbstractIoRegistry {
+        private static InstanceBased INSTANCE = new InstanceBased();
+
+        private InstanceBased() {
+            register(GryoIo.class, IoX.class, null);
+        }
+
+        public static InstanceBased getInstance() {
+            return INSTANCE;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java
new file mode 100644
index 0000000..ddbb221
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+/**
+ * A test class to be serialized.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoY {
+    private Integer y;
+    private Integer z;
+
+    private IoY() {}
+
+    public IoY(final int y, final int z) {
+        this.y = y;
+        this.z = z;
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final IoY ioY = (IoY) o;
+
+        return y.equals(ioY.y);
+
+    }
+
+    @Override
+    public int hashCode() {
+        return y.hashCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
new file mode 100644
index 0000000..1d03500
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoYIoRegistry {
+    public static class ConstructorBased extends AbstractIoRegistry {
+        public ConstructorBased() {
+            register(GryoIo.class, IoY.class, null);
+        }
+    }
+
+    public static class InstanceBased extends AbstractIoRegistry {
+        private static InstanceBased INSTANCE = new InstanceBased();
+
+        private InstanceBased() {
+            register(GryoIo.class, IoY.class, null);
+        }
+
+        public static InstanceBased getInstance() {
+            return INSTANCE;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
index 21bc5bc..b500495 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
@@ -18,8 +18,22 @@
  */
 package org.apache.tinkerpop.gremlin.structure.io.gryo;
 
+import org.apache.tinkerpop.gremlin.structure.io.IoX;
+import org.apache.tinkerpop.gremlin.structure.io.IoXIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoY;
+import org.apache.tinkerpop.gremlin.structure.io.IoYIoRegistry;
+import org.apache.tinkerpop.shaded.kryo.Kryo;
+import org.apache.tinkerpop.shaded.kryo.io.Input;
+import org.apache.tinkerpop.shaded.kryo.io.Output;
 import org.junit.Test;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotSame;
 
 /**
@@ -27,8 +41,62 @@ import static org.junit.Assert.assertNotSame;
  */
 public class GryoMapperTest {
     @Test
-    public void shouldGetMostRecentVersion() {
+    public void shouldMakeNewInstance() {
         final GryoMapper.Builder b = GryoMapper.build();
         assertNotSame(b, GryoMapper.build());
     }
+
+    @Test
+    public void shouldRegisterMultipleIoRegistryToSerialize() throws Exception {
+        final GryoMapper mapper = GryoMapper.build()
+                .addRegistry(IoXIoRegistry.InstanceBased.getInstance())
+                .addRegistry(IoYIoRegistry.InstanceBased.getInstance()).create();
+        final Kryo kryo = mapper.createMapper();
+        try (final OutputStream stream = new ByteArrayOutputStream()) {
+            final Output out = new Output(stream);
+            final IoX x = new IoX("x");
+            final IoY y = new IoY(100, 200);
+            kryo.writeClassAndObject(out, x);
+            kryo.writeClassAndObject(out, y);
+
+            try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
+                final Input input = new Input(inputStream);
+                final IoX readX = (IoX) kryo.readClassAndObject(input);
+                final IoY readY = (IoY) kryo.readClassAndObject(input);
+                assertEquals(x, readX);
+                assertEquals(y, readY);
+            }
+        }
+    }
+
+    @Test
+    public void shouldExpectReadFailureAsIoRegistryOrderIsNotRespected() throws Exception {
+        final GryoMapper mapperWrite = GryoMapper.build()
+                .addRegistry(IoXIoRegistry.InstanceBased.getInstance())
+                .addRegistry(IoYIoRegistry.InstanceBased.getInstance()).create();
+
+        final GryoMapper mapperRead = GryoMapper.build()
+                .addRegistry(IoYIoRegistry.InstanceBased.getInstance())
+                .addRegistry(IoXIoRegistry.InstanceBased.getInstance()).create();
+
+        final Kryo kryoWriter = mapperWrite.createMapper();
+        final Kryo kryoReader = mapperRead.createMapper();
+        try (final OutputStream stream = new ByteArrayOutputStream()) {
+            final Output out = new Output(stream);
+            final IoX x = new IoX("x");
+            final IoY y = new IoY(100, 200);
+            kryoWriter.writeClassAndObject(out, x);
+            kryoWriter.writeClassAndObject(out, y);
+
+            try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
+                final Input input = new Input(inputStream);
+
+                // kryo will read a IoY instance as we've reversed the registries.  it is neither an X or a Y
+                // so assert that both are incorrect
+                final IoY readY = (IoY) kryoReader.readClassAndObject(input);
+                assertNotEquals(y, readY);
+                assertNotEquals(x, readY);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
index 8a033c6..ea4bac7 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
@@ -21,6 +21,10 @@ package org.apache.tinkerpop.gremlin.structure.io.gryo;
 import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoX;
+import org.apache.tinkerpop.gremlin.structure.io.IoXIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoY;
+import org.apache.tinkerpop.gremlin.structure.io.IoYIoRegistry;
 import org.apache.tinkerpop.gremlin.util.function.FunctionUtils;
 import org.junit.Test;
 
@@ -83,24 +87,34 @@ public class GryoPoolTest {
     @Test
     public void shouldConfigPoolOnConstructionWithCustomIoRegistryConstructor() throws Exception {
         final Configuration conf = new BaseConfiguration();
-        conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistryConstructorBased.class.getName());
+        conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, IoXIoRegistry.ConstructorBased.class.getName());
         final GryoPool pool = new GryoPool(conf);
-        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
     }
 
     @Test
     public void shouldConfigPoolOnConstructionWithCustomIoRegistryInstance() throws Exception {
         final Configuration conf = new BaseConfiguration();
-        conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistryInstanceBased.class.getName());
+        conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, IoXIoRegistry.InstanceBased.class.getName());
         final GryoPool pool = new GryoPool(conf);
-        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
+    }
+
+    @Test
+    public void shouldConfigPoolOnConstructionWithMultipleCustomIoRegistries() throws Exception {
+        final Configuration conf = new BaseConfiguration();
+        conf.setProperty(GryoPool.CONFIG_IO_REGISTRY,
+                IoXIoRegistry.InstanceBased.class.getName() + "," + IoYIoRegistry.InstanceBased.class.getName());
+        final GryoPool pool = new GryoPool(conf);
+        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
+        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoY(100, 200), IoY.class);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void shouldConfigPoolOnConstructionWithoutCustomIoRegistryAndFail() throws Exception {
         final Configuration conf = new BaseConfiguration();
         final GryoPool pool = new GryoPool(conf);
-        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+        assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
     }
 
     @Test(expected = IllegalStateException.class)
@@ -120,48 +134,4 @@ public class GryoPoolTest {
             }
         }
     }
-
-    public static class Junk {
-        private String x;
-
-        private Junk() {}
-
-        public Junk(final String x) {
-            this.x = x;
-        }
-
-        @Override
-        public boolean equals(final Object o) {
-            if (this == o) return true;
-            if (o == null || getClass() != o.getClass()) return false;
-
-            final Junk junk = (Junk) o;
-
-            return x.equals(junk.x);
-
-        }
-
-        @Override
-        public int hashCode() {
-            return x.hashCode();
-        }
-    }
-
-    public static class CustomIoRegistryConstructorBased extends AbstractIoRegistry {
-        public CustomIoRegistryConstructorBased() {
-            register(GryoIo.class, Junk.class, null);
-        }
-    }
-
-    public static class CustomIoRegistryInstanceBased extends AbstractIoRegistry {
-        private static CustomIoRegistryInstanceBased INSTANCE = new CustomIoRegistryInstanceBased();
-
-        private CustomIoRegistryInstanceBased() {
-            register(GryoIo.class, Junk.class, null);
-        }
-
-        public static CustomIoRegistryInstanceBased getInstance() {
-            return INSTANCE;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
index 1c63046..04742ac 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
@@ -26,16 +26,17 @@ import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
 import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper;
 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.io.ByteArrayOutputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Method;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -44,7 +45,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.UUID;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -64,6 +64,7 @@ public final class GryoMessageSerializerV1d0 implements MessageSerializer {
     private static final String MIME_TYPE = SerTokens.MIME_GRYO_V1D0;
     private static final String MIME_TYPE_STRINGD = SerTokens.MIME_GRYO_V1D0 + "-stringd";
 
+    private static final String TOKEN_IO_REGISTRIES = "ioRegistries";
     private static final String TOKEN_CUSTOM = "custom";
     private static final String TOKEN_SERIALIZE_RESULT_TO_STRING = "serializeResultToString";
     private static final String TOKEN_USE_MAPPER_FROM_GRAPH = "useMapperFromGraph";
@@ -109,13 +110,38 @@ public final class GryoMessageSerializerV1d0 implements MessageSerializer {
             builder = GryoMapper.build();
         }
 
-        final List<String> classNameList;
-        try {
-            classNameList = (List<String>) config.getOrDefault(TOKEN_CUSTOM, new ArrayList<String>());
-        } catch (Exception ex) {
-            throw new IllegalStateException(String.format("Invalid configuration value of [%s] for [%s] setting on %s serialization configuration",
-                    config.getOrDefault(TOKEN_CUSTOM, ""), TOKEN_CUSTOM, this.getClass().getName()), ex);
-        }
+        addIoRegistries(config, builder);
+        addCustomClasses(config, builder);
+
+        this.serializeToString = Boolean.parseBoolean(config.getOrDefault(TOKEN_SERIALIZE_RESULT_TO_STRING, "false").toString());
+
+        this.gryoMapper = builder.create();
+    }
+
+    private void addIoRegistries(final Map<String, Object> config, final GryoMapper.Builder builder) {
+        final List<String> classNameList = getClassNamesFromConfig(TOKEN_IO_REGISTRIES, config);
+
+        classNameList.stream().forEach(className -> {
+            try {
+                final Class<?> clazz = Class.forName(className);
+                try {
+                    final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
+                    if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
+                        builder.addRegistry((IoRegistry) instanceMethod.invoke(null));
+                    else
+                        throw new Exception();
+                } catch (Exception methodex) {
+                    // tried getInstance() and that failed so try newInstance() no-arg constructor
+                    builder.addRegistry((IoRegistry) clazz.newInstance());
+                }
+            } catch (Exception ex) {
+                throw new IllegalStateException(ex);
+            }
+        });
+    }
+
+    private void addCustomClasses(final Map<String, Object> config, final GryoMapper.Builder builder) {
+        final List<String> classNameList = getClassNamesFromConfig(TOKEN_CUSTOM, config);
 
         classNameList.stream().forEach(serializerDefinition -> {
             String className;
@@ -145,10 +171,17 @@ public final class GryoMessageSerializerV1d0 implements MessageSerializer {
                 throw new IllegalStateException("Class could not be found", ex);
             }
         });
+    }
 
-        this.serializeToString = Boolean.parseBoolean(config.getOrDefault(TOKEN_SERIALIZE_RESULT_TO_STRING, "false").toString());
-
-        this.gryoMapper = builder.create();
+    private List<String> getClassNamesFromConfig(final String token, final Map<String, Object> config) {
+        final List<String> classNameList;
+        try {
+            classNameList = (List<String>) config.getOrDefault(token, new ArrayList<String>());
+        } catch (Exception ex) {
+            throw new IllegalStateException(String.format("Invalid configuration value of [%s] for [%s] setting on %s serialization configuration",
+                    config.getOrDefault(token, ""), token, this.getClass().getName()), ex);
+        }
+        return classNameList;
     }
 
     @Override