Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1564 1e186268c -> f2212025d


through hell and back to get IoRegistries loaded into Akka GryoSerializer. 
Phew. Learned a bunch about Akka Config.


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

Branch: refs/heads/TINKERPOP-1564
Commit: f2212025db834e0259ada646ec32f92c31b9e038
Parents: 1e18626
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Fri Jan 13 08:52:00 2017 -0700
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Fri Jan 13 08:52:00 2017 -0700

----------------------------------------------------------------------
 .../akka/process/actors/ActorMailbox.java       |  2 +-
 .../akka/process/actors/AkkaConfigFactory.java  | 14 ++----
 .../process/actors/io/gryo/GryoSerializer.java  | 49 ++++++++++++++++++--
 .../tinkerpop/gremlin/util/ClassUtil.java       | 40 ++++++++++++++++
 4 files changed, 89 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f2212025/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/ActorMailbox.java
----------------------------------------------------------------------
diff --git 
a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/ActorMailbox.java
 
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/ActorMailbox.java
index 8087038..d45eda3 100644
--- 
a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/ActorMailbox.java
+++ 
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/ActorMailbox.java
@@ -121,7 +121,7 @@ public final class ActorMailbox implements MailboxType, 
ProducesMessageQueue<Act
     // This constructor signature must exist, it will be called by Akka
     public ActorMailbox(final ActorSystem.Settings settings, final Config 
config) {
         try {
-            final String[] messages = ((String) 
settings.config().getAnyRef("message-priorities")).replace("[", 
"").replace("]", "").split(",");
+            final List<String> messages = 
config.getStringList("message-priorities");
             for (final String clazz : messages) {
                 this.messagePriorities.add(Class.forName(clazz.trim()));
             }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f2212025/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java
----------------------------------------------------------------------
diff --git 
a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java
 
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java
index c20e380..6364de3 100644
--- 
a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java
+++ 
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/AkkaConfigFactory.java
@@ -29,6 +29,7 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.akka.process.actors.io.gryo.GryoSerializer;
 import org.apache.tinkerpop.gremlin.process.actors.ActorProgram;
 import org.apache.tinkerpop.gremlin.structure.Partition;
+import org.apache.tinkerpop.gremlin.util.ClassUtil;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -48,24 +49,17 @@ final class AkkaConfigFactory {
     }
 
     static Config generateAkkaConfig(final ActorProgram actorProgram, final 
Configuration configuration) {
-        final Map<String, String> registeredGryoClasses = new HashMap<>();
-        new 
GryoSerializer().getGryoMapper().getRegisteredClasses().stream().filter(clazz 
-> !clazz.isArray()).forEach(clazz -> {
-            int index = clazz.getCanonicalName().lastIndexOf(".");
-            registeredGryoClasses.put(null == clazz.getEnclosingClass() ?
-                    clazz.getCanonicalName() :
-                    clazz.getCanonicalName().substring(0, index) + "$" + 
clazz.getCanonicalName().substring(index + 1), "gryo");
-        });
         Config config = ConfigFactory.defaultApplication().
-                withValue("akka.actor.serialization-bindings", 
ConfigValueFactory.fromMap(registeredGryoClasses)).
+                withValue("akka.actor.serialization-bindings", 
ConfigValueFactory.fromMap(GryoSerializer.getSerializerBindings(configuration))).
                 withValue("custom-dispatcher.mailbox-requirement", 
ConfigValueFactory.fromAnyRef(ActorMailbox.class.getCanonicalName() + "$" + 
ActorMailbox.ActorSemantics.class.getSimpleName())).
                 withValue("custom-dispatcher-mailbox.mailbox-type", 
ConfigValueFactory.fromAnyRef(ActorMailbox.class.getCanonicalName())).
                 withValue("akka.actor.mailbox.requirements", 
ConfigValueFactory.fromMap(Collections.singletonMap(ActorMailbox.class.getCanonicalName()
 + "$" + ActorMailbox.ActorSemantics.class.getSimpleName(), 
"custom-dispatcher-mailbox"))).
-                withValue("message-priorities",
+                withValue("custom-dispatcher-mailbox.message-priorities",
                         
ConfigValueFactory.fromAnyRef(actorProgram.getMessagePriorities().
                                 
orElse(Collections.singletonList(Object.class)).
                                 stream().
                                 map(Class::getCanonicalName).
-                                collect(Collectors.toList()).toString()));
+                                collect(Collectors.toList())));
         final Iterator<String> keys = configuration.getKeys();
         while (keys.hasNext()) {
             final String key = keys.next();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f2212025/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/io/gryo/GryoSerializer.java
----------------------------------------------------------------------
diff --git 
a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/io/gryo/GryoSerializer.java
 
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/io/gryo/GryoSerializer.java
index 8f55e32..5183e6f 100644
--- 
a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/io/gryo/GryoSerializer.java
+++ 
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actors/io/gryo/GryoSerializer.java
@@ -19,8 +19,11 @@
 
 package org.apache.tinkerpop.gremlin.akka.process.actors.io.gryo;
 
+import akka.actor.ExtendedActorSystem;
 import akka.serialization.Serializer;
-import org.apache.tinkerpop.gremlin.process.actors.Address;
+import com.typesafe.config.Config;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
 import 
org.apache.tinkerpop.gremlin.process.actors.traversal.message.BarrierAddMessage;
 import 
org.apache.tinkerpop.gremlin.process.actors.traversal.message.BarrierDoneMessage;
 import 
org.apache.tinkerpop.gremlin.process.actors.traversal.message.SideEffectAddMessage;
@@ -28,14 +31,21 @@ import 
org.apache.tinkerpop.gremlin.process.actors.traversal.message.SideEffectS
 import 
org.apache.tinkerpop.gremlin.process.actors.traversal.message.StartMessage;
 import org.apache.tinkerpop.gremlin.process.actors.traversal.message.Terminate;
 import org.apache.tinkerpop.gremlin.process.actors.util.DefaultActorsResult;
+import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoPool;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoVersion;
+import org.apache.tinkerpop.gremlin.structure.io.util.IoRegistryHelper;
+import org.apache.tinkerpop.gremlin.util.ClassUtil;
 import org.apache.tinkerpop.shaded.kryo.io.Input;
 import org.apache.tinkerpop.shaded.kryo.io.Output;
 import scala.Option;
 
 import java.io.ByteArrayOutputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -44,13 +54,23 @@ public final class GryoSerializer implements Serializer {
 
     private final GryoPool gryoPool;
 
-    public GryoSerializer() {
+    public GryoSerializer(final ExtendedActorSystem actorSystem) {
+        final Config config = actorSystem.settings().config();
+        final List<IoRegistry> registryList;
+        if (config.hasPath(IoRegistry.IO_REGISTRY)) {
+            final Configuration configuration = new BaseConfiguration();
+            configuration.setProperty(IoRegistry.IO_REGISTRY, 
config.getAnyRef(IoRegistry.IO_REGISTRY));
+            registryList = IoRegistryHelper.createRegistries(configuration);
+        } else {
+            registryList = Collections.emptyList();
+        }
         this.gryoPool = GryoPool.build().
                 poolSize(10).
                 initializeMapper(builder ->
                         builder.referenceTracking(true).
                                 registrationRequired(true).
                                 version(GryoVersion.V3_0).
+                                addRegistries(registryList).
                                 addCustom(
                                         Terminate.class,
                                         StartMessage.class,
@@ -61,10 +81,29 @@ public final class GryoSerializer implements Serializer {
                                         DefaultActorsResult.class)).create();
     }
 
-    public GryoMapper getGryoMapper() {
-        return this.gryoPool.getMapper();
+    public static Map<String, String> getSerializerBindings(final 
Configuration configuration) {
+        final Map<String, String> bindings = new HashMap<>();
+        GryoMapper.build().
+                referenceTracking(true).
+                registrationRequired(true).
+                version(GryoVersion.V3_0).
+                
addRegistries(IoRegistryHelper.createRegistries(configuration)).
+                addCustom(
+                        Terminate.class,
+                        StartMessage.class,
+                        BarrierAddMessage.class,
+                        BarrierDoneMessage.class,
+                        SideEffectSetMessage.class,
+                        SideEffectAddMessage.class,
+                        DefaultActorsResult.class).
+                create().
+                getRegisteredClasses().
+                stream().
+                filter(clazz -> !clazz.isArray()). // be sure to make this 
right somehow
+                forEach(clazz -> bindings.put(ClassUtil.getClassName(clazz), 
"gryo"));
+        return bindings;
     }
-
+    
     @Override
     public int identifier() {
         return GryoVersion.V3_0.hashCode();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f2212025/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ClassUtil.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ClassUtil.java 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ClassUtil.java
new file mode 100644
index 0000000..5989f1a
--- /dev/null
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/ClassUtil.java
@@ -0,0 +1,40 @@
+/*
+ *  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.util;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class ClassUtil {
+
+    private ClassUtil() {
+        // static method class
+    }
+
+    public static String getClassName(final Class<?> clazz) {
+        if (null == clazz.getEnclosingClass())
+            return clazz.getCanonicalName();
+        else {
+            final String className = clazz.getCanonicalName();
+            int index = className.lastIndexOf(".");
+            return className.substring(0, index) + "$" + 
className.substring(index + 1);
+        }
+    }
+}

Reply via email to