You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2017/01/03 14:44:08 UTC

[22/24] tinkerpop git commit: tweaks to IoRegistryHelper now that instance() is the default instead of getInstance(). Minor tweaks here and there otheriwse. Rebased with master/.

tweaks to IoRegistryHelper now that instance() is the default instead of getInstance(). Minor tweaks here and there otheriwse. Rebased with master/.


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

Branch: refs/heads/master
Commit: 41892072261b8bf3ccdd9d8e3f44c8706dc1474e
Parents: f7b71b3
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Nov 29 05:51:10 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Nov 29 05:51:10 2016 -0700

----------------------------------------------------------------------
 .../gremlin/structure/io/gryo/GryoPool.java     |  2 +-
 .../structure/io/util/IoRegistryHelper.java     | 24 ++++++++++++--------
 .../hadoop/structure/io/gryo/ToyIoRegistry.java |  2 +-
 .../process/computer/SparkGraphComputer.java    | 23 ++++++++-----------
 .../spark/structure/io/gryo/GryoSerializer.java |  2 +-
 5 files changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41892072/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 5fc15a3..4e3ab13 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
@@ -217,4 +217,4 @@ public final class GryoPool {
             return gryoPool;
         }
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41892072/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/IoRegistryHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/IoRegistryHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/IoRegistryHelper.java
index d1fac40..0688e6f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/IoRegistryHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/util/IoRegistryHelper.java
@@ -47,18 +47,22 @@ public final class IoRegistryHelper {
             else if (object instanceof String || object instanceof Class) {
                 try {
                     final Class<?> clazz = object instanceof String ? Class.forName((String) object) : (Class) object;
+                    Method instanceMethod = null;
                     try {
-                        final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
-                        if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
-                            registries.add((IoRegistry) instanceMethod.invoke(null));
-                        else
-                            throw new Exception();
-                    } catch (final Exception methodex) {
-                        // tried getInstance() and that failed so try newInstance() no-arg constructor
-                        registries.add((IoRegistry) clazz.newInstance());
+                        instanceMethod = clazz.getDeclaredMethod("instance"); // try for getInstance() ??
+                    } catch (final NoSuchMethodException e) {
+                        try {
+                            instanceMethod = clazz.getDeclaredMethod("getInstance"); // try for getInstance() ??
+                        } catch (final NoSuchMethodException e2) {
+                            // no instance() or getInstance() methods
+                        }
                     }
-                } catch (final Exception ex) {
-                    throw new IllegalStateException(ex.getMessage(), ex);
+                    if (null != instanceMethod && IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
+                        registries.add((IoRegistry) instanceMethod.invoke(null));
+                    else
+                        registries.add((IoRegistry) clazz.newInstance()); // no instance() or getInstance() methods, try instantiate class
+                } catch (final Exception e) {
+                    throw new IllegalStateException(e.getMessage(), e);
                 }
             } else {
                 throw new IllegalArgumentException("The provided registry object can not be resolved to an instance: " + object);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41892072/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/ToyIoRegistry.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/ToyIoRegistry.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/ToyIoRegistry.java
index 515d213..26d87a9 100644
--- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/ToyIoRegistry.java
+++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/gryo/ToyIoRegistry.java
@@ -64,7 +64,7 @@ public final class ToyIoRegistry extends AbstractIoRegistry {
         }
     }
 
-    public static ToyIoRegistry getInstance() {
+    public static ToyIoRegistry instance() {
         return INSTANCE;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41892072/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkGraphComputer.java
----------------------------------------------------------------------
diff --git a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkGraphComputer.java b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkGraphComputer.java
index ee3ebe1..2403f46 100644
--- a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkGraphComputer.java
+++ b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkGraphComputer.java
@@ -69,6 +69,7 @@ import org.apache.tinkerpop.gremlin.spark.structure.io.OutputRDD;
 import org.apache.tinkerpop.gremlin.spark.structure.io.PersistedInputRDD;
 import org.apache.tinkerpop.gremlin.spark.structure.io.PersistedOutputRDD;
 import org.apache.tinkerpop.gremlin.spark.structure.io.SparkContextStorage;
+import org.apache.tinkerpop.gremlin.spark.structure.io.gryo.GryoRegistrator;
 import org.apache.tinkerpop.gremlin.spark.structure.io.gryo.kryoshim.unshaded.UnshadedKryoShimService;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
@@ -77,8 +78,7 @@ import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShimServiceLo
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.Executor;
@@ -96,15 +96,9 @@ public final class SparkGraphComputer extends AbstractHadoopGraphComputer {
     private boolean workersSet = false;
     private final ThreadFactory threadFactoryBoss = new BasicThreadFactory.Builder().namingPattern(SparkGraphComputer.class.getSimpleName() + "-boss").build();
 
-    private static final Set<String> KEYS_PASSED_IN_JVM_SYSTEM_PROPERTIES;
-
-    static
-    {
-        Set<String> s = new HashSet<>();
-        s.add(KryoShimServiceLoader.KRYO_SHIM_SERVICE);
-        s.add(IoRegistry.IO_REGISTRY);
-        KEYS_PASSED_IN_JVM_SYSTEM_PROPERTIES = Collections.unmodifiableSet(s);
-    }
+    private static final Set<String> KEYS_PASSED_IN_JVM_SYSTEM_PROPERTIES = new HashSet<>(Arrays.asList(
+            KryoShimServiceLoader.KRYO_SHIM_SERVICE,
+            IoRegistry.IO_REGISTRY));
 
     /**
      * An {@code ExecutorService} that schedules up background work. Since a {@link GraphComputer} is only used once
@@ -178,8 +172,11 @@ public final class SparkGraphComputer extends AbstractHadoopGraphComputer {
             //////////////////////////////////////////////////
             // apache and hadoop configurations that are used throughout the graph computer computation
             final org.apache.commons.configuration.Configuration graphComputerConfiguration = new HadoopConfiguration(this.sparkConfiguration);
-            // TODO !! if (!graphComputerConfiguration.containsKey(Constants.SPARK_SERIALIZER))
-            //    graphComputerConfiguration.setProperty(Constants.SPARK_SERIALIZER, GryoSerializer.class.getCanonicalName());
+            if (!graphComputerConfiguration.containsKey(Constants.SPARK_SERIALIZER)) {
+                graphComputerConfiguration.setProperty(Constants.SPARK_SERIALIZER, KryoSerializer.class.getCanonicalName());
+                if (!graphComputerConfiguration.containsKey(Constants.SPARK_KRYO_REGISTRATOR))
+                    graphComputerConfiguration.setProperty(Constants.SPARK_KRYO_REGISTRATOR, GryoRegistrator.class.getCanonicalName());
+            }
             graphComputerConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER_HAS_EDGES, this.persist.equals(GraphComputer.Persist.EDGES));
             final Configuration hadoopConfiguration = ConfUtil.makeHadoopConfiguration(graphComputerConfiguration);
             final Storage fileSystemStorage = FileSystemStorage.open(hadoopConfiguration);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/41892072/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/structure/io/gryo/GryoSerializer.java
----------------------------------------------------------------------
diff --git a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/structure/io/gryo/GryoSerializer.java b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/structure/io/gryo/GryoSerializer.java
index 60c0873..c1e52ea 100644
--- a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/structure/io/gryo/GryoSerializer.java
+++ b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/structure/io/gryo/GryoSerializer.java
@@ -152,7 +152,7 @@ public final class GryoSerializer extends Serializer implements Serializable {
             }
         }
 
-        public static SparkIoRegistry getInstance() {
+        public static SparkIoRegistry instance() {
             return INSTANCE;
         }
     }