tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [32/50] [abbrv] tinkerpop git commit: having to redesign our concept of Attachable.attach() and detach(). @spmallette's Host interface now has a default method of Host.attach(t). Moreover, Traverser now has Traverser.attach(Host). Vertex extends Host. Gr
Date Thu, 19 Jan 2017 17:40:38 GMT
having to redesign our concept of Attachable.attach() and detach(). @spmallette's Host interface
now has a default method of Host.attach(t). Moreover, Traverser now has Traverser.attach(Host).
Vertex extends Host. Graph extends Host... and now Partition extends Host. Instead of leaving
the logic up to Attachable.Method, we need to leave it up to the Vertex/Graph/Partition implementation
-- why? Well, StarVertex will be able to attach local stuff. TinkerGraph will be able to attach
globally. Partitions, local to their partition. etc. etc. In a future push, we will need to
have dynamic Traverser.detach() logic. Traverser.detach(DetachFactory).


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

Branch: refs/heads/TINKERPOP-1564
Commit: f375c92006b1f0b36433dbe41c7d130b4e3364bb
Parents: 0e7b6ae
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Jan 11 16:43:23 2017 -0700
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Thu Jan 19 10:27:16 2017 -0700

----------------------------------------------------------------------
 .../actors/traversal/TraversalActorProgram.java |  2 ++
 .../traversal/TraversalMasterProgram.java       |  6 ++--
 .../traversal/TraversalWorkerProgram.java       |  6 ++--
 .../gremlin/process/traversal/Traverser.java    |  4 +++
 .../traverser/B_LP_O_P_S_SE_SL_Traverser.java   | 11 ++++++
 .../traverser/B_LP_O_S_SE_SL_Traverser.java     | 12 +++++++
 .../traverser/LP_O_OB_P_S_SE_SL_Traverser.java  | 11 ++++++
 .../traverser/LP_O_OB_S_SE_SL_Traverser.java    | 11 ++++++
 .../traverser/util/AbstractTraverser.java       | 11 ++++++
 .../traverser/util/EmptyTraverser.java          |  6 ++++
 .../traverser/util/OrderedTraverser.java        | 10 +++++-
 .../tinkerpop/gremlin/structure/Partition.java  |  3 ++
 .../gremlin/structure/Partitioner.java          |  6 ++--
 .../gremlin/structure/util/Attachable.java      |  6 ++--
 .../tinkerpop/gremlin/structure/util/Host.java  |  5 +++
 .../util/partitioner/GlobalPartitioner.java     | 35 +++++++++++++-------
 .../util/partitioner/HashPartitioner.java       | 21 ++++++++++--
 17 files changed, 139 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalActorProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalActorProgram.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalActorProgram.java
index c97ffd7..22add26 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalActorProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalActorProgram.java
@@ -57,6 +57,8 @@ import java.util.Optional;
  */
 public final class TraversalActorProgram<R> implements ActorProgram, Serializable {
 
+    public static boolean DETACH = true;
+
     public static final String TRAVERSAL_ACTOR_PROGRAM_BYTECODE = "gremlin.traversalActorProgram.bytecode";
 
     private static final List<Class> MESSAGE_PRIORITIES = Arrays.asList(

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalMasterProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalMasterProgram.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalMasterProgram.java
index 796e4c1..c011822 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalMasterProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalMasterProgram.java
@@ -180,11 +180,11 @@ final class TraversalMasterProgram implements ActorProgram.Master<Object>
{
     }
 
     private final Traverser.Admin detachTraverser(final Traverser.Admin traverser) {
-        return true ? traverser : traverser.detach();
+        return TraversalActorProgram.DETACH ? traverser.detach() : traverser;
     }
 
     private void attachTraverser(final Traverser.Admin traverser) {
-        if (false && traverser.get() instanceof Element)
-            traverser.attach(Attachable.Method.get(this.master.partitioner().getPartition((Element)
traverser.get())));
+        if (TraversalActorProgram.DETACH && traverser.get() instanceof Element)
+            traverser.attach(this.master.partitioner().getPartition((Element) traverser.get()));
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalWorkerProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalWorkerProgram.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalWorkerProgram.java
index fa5645d..abda752 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalWorkerProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actors/traversal/TraversalWorkerProgram.java
@@ -177,12 +177,12 @@ final class TraversalWorkerProgram implements ActorProgram.Worker<Object>
{
     }
 
     private final Traverser.Admin detachTraverser(final Traverser.Admin traverser) {
-        return true ? traverser : traverser.detach();
+        return TraversalActorProgram.DETACH ? traverser.detach() : traverser;
     }
 
     private final Traverser.Admin attachTraverser(final Traverser.Admin traverser) {
-        if (false)
-            traverser.attach(Attachable.Method.get(this.self.partition()));
+        if (TraversalActorProgram.DETACH)
+            traverser.attach(this.self.partition());
         return traverser;
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
index 93ebe7d..682096b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traverser.java
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.process.traversal;
 
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 
 import java.io.Serializable;
 import java.util.Set;
@@ -280,6 +281,9 @@ public interface Traverser<T> extends Serializable, Comparable<Traverser<T>>,
Cl
         @Override
         public T attach(final Function<Attachable<T>, T> method);
 
+
+        public Traverser.Admin<T> attach(final Host host);
+
         /**
          * Set the sideEffects of the {@link Traversal}. Given that traversers can move between
machines,
          * it may be important to re-set this when the traverser crosses machine boundaries.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
index 49f19e4..02f3306 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
@@ -22,6 +22,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Path;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Partition;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
 
 import java.util.Set;
@@ -57,6 +60,14 @@ public class B_LP_O_P_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
         return this;
     }
 
+    @Override
+    public Traverser.Admin<T> attach(final Host host) {
+        super.attach(host);
+        if (host instanceof Partition || host instanceof Graph)
+            this.path = host.attach(this.path);
+        return this;
+    }
+
     /////////////////
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
index fc16366..5da2c2d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
@@ -23,6 +23,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Pop;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Partition;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
 
 import java.util.HashSet;
@@ -61,6 +64,15 @@ public class B_LP_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
         return this;
     }
 
+    @Override
+    public Traverser.Admin<T> attach(final Host host) {
+        super.attach(host);
+        if (host instanceof Partition || host instanceof Graph)
+            this.path = host.attach(this.path);
+        return this;
+    }
+
+
     /////////////////
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
index 5f24e8c..4b0d9a7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
@@ -23,6 +23,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Path;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Partition;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
 
 import java.util.HashSet;
@@ -59,6 +62,14 @@ public class LP_O_OB_P_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
         return this;
     }
 
+    @Override
+    public Traverser.Admin<T> attach(final Host host) {
+        super.attach(host);
+        if (host instanceof Partition || host instanceof Graph)
+            this.path = host.attach(this.path);
+        return this;
+    }
+
     /////////////////
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
index 58f420c..fe60e9e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
@@ -24,6 +24,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.Pop;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ImmutablePath;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Partition;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
 
 import java.util.Set;
@@ -61,6 +64,14 @@ public class LP_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
         return this;
     }
 
+    @Override
+    public Traverser.Admin<T> attach(final Host host) {
+        super.attach(host);
+        if (host instanceof Partition || host instanceof Graph)
+            this.path = host.attach(this.path);
+        return this;
+    }
+
     /////////////////
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
index 50a206b..0711182 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/AbstractTraverser.java
@@ -24,7 +24,10 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyPath;
 import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversalSideEffects;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Partition;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceFactory;
 
 import java.util.Set;
@@ -138,6 +141,14 @@ public abstract class AbstractTraverser<T> implements Traverser<T>,
Traverser.Ad
     }
 
     @Override
+    public Admin<T> attach(final Host host) {
+        // you do not want to attach a path because it will reference graph objects not at
the current vertex
+        if (!(this.t instanceof Path) || host instanceof Graph || host instanceof Partition)
+            this.t = host.attach(this.t);
+        return this;
+    }
+
+    @Override
     public void setSideEffects(final TraversalSideEffects sideEffects) {
 
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
index 7c99cb5..54371c7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/EmptyTraverser.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyPath;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 
 import java.util.Collections;
 import java.util.Set;
@@ -70,6 +71,11 @@ public final class EmptyTraverser<T> implements Traverser<T>,
Traverser.Admin<T>
     }
 
     @Override
+    public Traverser.Admin<T> attach(final Host host) {
+        return this;
+    }
+
+    @Override
     public void incrLoops(final String stepLabel) {
 
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/OrderedTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/OrderedTraverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/OrderedTraverser.java
index 3be67a2..1294562 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/OrderedTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/util/OrderedTraverser.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.Host;
 
 import java.util.Set;
 import java.util.function.Function;
@@ -112,7 +113,8 @@ public final class OrderedTraverser<T> implements Traverser.Admin<T>
{
 
     @Override
     public Admin<T> detach() {
-        return this.internal.detach();
+        this.internal.detach();
+        return this;
     }
 
     @Override
@@ -121,6 +123,12 @@ public final class OrderedTraverser<T> implements Traverser.Admin<T>
{
     }
 
     @Override
+    public Admin<T> attach(final Host host) {
+        this.internal = this.internal.attach(host);
+        return this;
+    }
+
+    @Override
     public void setSideEffects(final TraversalSideEffects sideEffects) {
         this.internal.setSideEffects(sideEffects);
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java
index 49389f1..b2d60d1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partition.java
@@ -19,6 +19,7 @@
 
 package org.apache.tinkerpop.gremlin.structure;
 
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
 import org.apache.tinkerpop.gremlin.structure.util.Host;
 
 import java.net.InetAddress;
@@ -76,6 +77,8 @@ public interface Partition extends Host {
      */
     public InetAddress location();
 
+    public Partitioner partitioner();
+
     public static interface PhysicalPartition extends Partition {
     }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partitioner.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partitioner.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partitioner.java
index 2e2cdb7..afd283c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partitioner.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Partitioner.java
@@ -26,13 +26,15 @@ import java.util.List;
  */
 public interface Partitioner {
 
+    public Graph getGraph();
+
     public List<Partition> getPartitions();
 
     public Partition getPartition(final Element element);
 
     public default Partition getPartition(final String id) {
-        for(final Partition partition : this.getPartitions()) {
-            if(partition.id().equals(id))
+        for (final Partition partition : this.getPartitions()) {
+            if (partition.id().equals(id))
                 return partition;
         }
         throw new IllegalArgumentException("The provided partition does not exist in the
partitioner");

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
index f748ee6..cbad51a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Attachable.java
@@ -186,7 +186,7 @@ public interface Attachable<V> {
         }
 
         public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex,
final Partition hostPartition) {
-            final Iterator<Vertex> iterator = hostPartition.vertices(attachableVertex.get().id());
+            final Iterator<Vertex> iterator = hostPartition.partitioner().getGraph().vertices(attachableVertex.get().id());
             return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.empty();
         }
 
@@ -207,7 +207,7 @@ public interface Attachable<V> {
         }
 
         public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge,
final Partition hostPartition) {
-            final Iterator<Edge> iterator = hostPartition.edges(attachableEdge.get().id());
+            final Iterator<Edge> iterator = hostPartition.partitioner().getGraph().edges(attachableEdge.get().id());
             return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.empty();
         }
 
@@ -238,7 +238,7 @@ public interface Attachable<V> {
 
         public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty>
attachableVertexProperty, final Partition hostPartition) {
             final VertexProperty baseVertexProperty = attachableVertexProperty.get();
-            final Iterator<Vertex> vertexIterator= hostPartition.vertices(baseVertexProperty.element().id());
+            final Iterator<Vertex> vertexIterator= hostPartition.partitioner().getGraph().vertices(baseVertexProperty.element().id());
             if (vertexIterator.hasNext()) {
                 final Iterator<VertexProperty<Object>> vertexPropertyIterator
= vertexIterator.next().properties(baseVertexProperty.key());
                 while (vertexPropertyIterator.hasNext()) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java
index 92962b0..7ceb728 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/Host.java
@@ -22,6 +22,11 @@ package org.apache.tinkerpop.gremlin.structure.util;
  * A marker interface that identifies an object as something that an {@link Attachable} can
connect to.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
 public interface Host {
+
+    public default <T> T attach(final T t) {
+        return t instanceof Attachable ? ((Attachable<T>) t).attach(Attachable.Method.get(this))
: t;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/GlobalPartitioner.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/GlobalPartitioner.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/GlobalPartitioner.java
index 397c113..af04dbe 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/GlobalPartitioner.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/partitioner/GlobalPartitioner.java
@@ -19,6 +19,7 @@
 
 package org.apache.tinkerpop.gremlin.structure.util.partitioner;
 
+import org.apache.commons.configuration.ConfigurationConverter;
 import org.apache.commons.configuration.MapConfiguration;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Element;
@@ -29,7 +30,6 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
-import java.io.Serializable;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.Collections;
@@ -44,9 +44,13 @@ import java.util.Map;
 public final class GlobalPartitioner implements Partitioner {
 
     private final GlobalPartition partition;
+    private transient Graph graph;
+    private final Map<String, Object> graphConfiguration;
 
     public GlobalPartitioner(final Graph graph) {
-        this.partition = new GlobalPartition(graph);
+        this.graph = graph;
+        this.graphConfiguration = (Map) ConfigurationConverter.getMap(graph.configuration());
+        this.partition = new GlobalPartition(this);
     }
 
     @Override
@@ -60,20 +64,26 @@ public final class GlobalPartitioner implements Partitioner {
     }
 
     @Override
+    public Graph getGraph() {
+        if (null == this.graph)
+            this.graph = GraphFactory.open(new MapConfiguration(this.graphConfiguration));
+        return this.graph;
+    }
+
+    @Override
     public String toString() {
         return StringFactory.partitionerString(this);
     }
 
     private class GlobalPartition implements Partition {
 
-        private transient Graph graph;
+        private final GlobalPartitioner partitioner;
         private final Map<String, Object> configuration = new HashMap<>();
         private final String id;
         private final InetAddress location;
 
-        private GlobalPartition(final Graph graph) {
-            this.graph = graph;
-            graph.configuration().getKeys().forEachRemaining(key -> configuration.put(key,
graph.configuration().getProperty(key)));
+        private GlobalPartition(final GlobalPartitioner partitioner) {
+            this.partitioner = partitioner;
             this.id = "global-" + graph.getClass().getSimpleName().toLowerCase();
             try {
                 this.location = InetAddress.getLocalHost();
@@ -89,16 +99,12 @@ public final class GlobalPartitioner implements Partitioner {
 
         @Override
         public Iterator<Vertex> vertices(final Object... ids) {
-            if(null == this.graph)
-                this.graph = GraphFactory.open(new MapConfiguration(this.configuration));
-            return this.graph.vertices(ids);
+            return this.partitioner.getGraph().vertices(ids);
         }
 
         @Override
         public Iterator<Edge> edges(final Object... ids) {
-            if(null == this.graph)
-                this.graph = GraphFactory.open(new MapConfiguration(this.configuration));
-            return this.graph.edges(ids);
+            return this.partitioner.getGraph().edges(ids);
         }
 
         @Override
@@ -125,6 +131,11 @@ public final class GlobalPartitioner implements Partitioner {
         public InetAddress location() {
             return this.location;
         }
+
+        @Override
+        public Partitioner partitioner() {
+            return this.partitioner;
+        }
     }
 }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f375c920/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
index 407ac72..3b1459d 100644
--- 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
@@ -21,6 +21,7 @@ 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.Graph;
 import org.apache.tinkerpop.gremlin.structure.Partition;
 import org.apache.tinkerpop.gremlin.structure.Partitioner;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -38,11 +39,13 @@ import java.util.List;
 public final class HashPartitioner implements Partitioner {
 
     private final List<Partition> partitions = new ArrayList<>();
+    private final Partitioner basePartitioner;
 
     public HashPartitioner(final Partitioner basePartitioner, final int splits) {
-        for (final Partition partition : basePartitioner.getPartitions()) {
+        this.basePartitioner = basePartitioner;
+        for (final Partition partition : this.basePartitioner.getPartitions()) {
             for (int i = 0; i < splits; i++) {
-                this.partitions.add(new HashPartition(partition, i, splits));
+                this.partitions.add(new HashPartition(this, partition, i, splits));
             }
         }
     }
@@ -53,6 +56,11 @@ public final class HashPartitioner implements Partitioner {
     }
 
     @Override
+    public Graph getGraph() {
+        return this.basePartitioner.getGraph();
+    }
+
+    @Override
     public List<Partition> getPartitions() {
         return this.partitions;
     }
@@ -68,12 +76,14 @@ public final class HashPartitioner implements Partitioner {
 
     private static final class HashPartition implements Partition {
 
+        private final HashPartitioner hashPartitioner;
         private final Partition basePartition;
         private final int totalSplits;
         private final int splitId;
         private final String id;
 
-        private HashPartition(final Partition basePartition, final int splitId, final int
totalSplits) {
+        private HashPartition(final HashPartitioner partitioner, final Partition basePartition,
final int splitId, final int totalSplits) {
+            this.hashPartitioner = partitioner;
             this.basePartition = basePartition;
             this.totalSplits = totalSplits;
             this.splitId = splitId;
@@ -119,6 +129,11 @@ public final class HashPartitioner implements Partitioner {
         public InetAddress location() {
             return this.basePartition.location();
         }
+
+        @Override
+        public Partitioner partitioner() {
+            return this.hashPartitioner;
+        }
     }
 }
 


Mime
View raw message