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/11 17:53:40 UTC

[32/50] [abbrv] tinkerpop git commit: created a new module called akka-gremlin. It will implement the actor/ package interfaces (yet to be defined in gremlin-core).

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eb877b7f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/HashPartitioner.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/HashPartitioner.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/HashPartitioner.java
new file mode 100644
index 0000000..432918f
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/HashPartitioner.java
@@ -0,0 +1,96 @@
+/*
+ *  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.util.partitioner;
+
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.Partition;
+import org.apache.tinkerpop.gremlin.structure.Partitioner;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class HashPartitioner implements Partitioner {
+
+    private final List<Partition> partitions = new ArrayList<>();
+
+    public HashPartitioner(final Partitioner basePartitioner, final int splits) {
+        for (final Partition partition : basePartitioner.getPartitions()) {
+            for (int i = 0; i < splits; i++) {
+                this.partitions.add(new HashPartition(partition, i, splits));
+            }
+        }
+    }
+
+    @Override
+    public List<Partition> getPartitions() {
+        return this.partitions;
+    }
+
+    @Override
+    public Partition getPartition(final Element element) {
+        for (final Partition partition : this.partitions) {
+            if (partition.contains(element))
+                return partition;
+        }
+        throw new IllegalArgumentException("The provided element is not in any known partition: " + element);
+    }
+
+    private static final class HashPartition implements Partition {
+
+        private final Partition basePartition;
+        private final int totalSplits;
+        private final int splitId;
+
+        private HashPartition(final Partition basePartition, final int splitId, final int totalSplits) {
+            this.basePartition = basePartition;
+            this.totalSplits = totalSplits;
+            this.splitId = splitId;
+        }
+
+        @Override
+        public boolean contains(final Element element) {
+            return (this.splitId == element.hashCode() % this.totalSplits) && this.basePartition.contains(element);
+        }
+
+        @Override
+        public Iterator<Vertex> vertices(final Object... ids) {
+            return IteratorUtils.filter(this.basePartition.vertices(ids), vertex -> this.splitId == vertex.hashCode() % this.totalSplits);
+        }
+
+        @Override
+        public Iterator<Edge> edges(final Object... ids) {
+            return IteratorUtils.filter(this.basePartition.edges(ids), edge -> this.splitId == edge.hashCode() % this.totalSplits);
+        }
+
+        @Override
+        public URI location() {
+            return this.basePartition.location();
+        }
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/eb877b7f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index f6c3cc4..d7b3865 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,6 +126,7 @@ limitations under the License.
         <module>gremlin-server</module>
         <module>gremlin-archetype</module>
         <module>gremlin-tools</module>
+        <module>akka-gremlin</module>
     </modules>
     <scm>
         <connection>scm:git:git@git-wip-us.apache.org:repos/asf/tinkerpop.git</connection>
@@ -299,6 +300,7 @@ limitations under the License.
                         <exclude>gremlin-console/bin/gremlin.sh</exclude>
                         <exclude>docs/site/home/css/**</exclude>
                         <exclude>docs/site/home/js/**</exclude>
+                        <exclude>**/resources/application.conf</exclude>
                     </excludes>
                     <licenses>
                         <license implementation="org.apache.rat.analysis.license.ApacheSoftwareLicense20"/>