incubator-giraph-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ach...@apache.org
Subject svn commit: r1226513 - in /incubator/giraph/trunk: ./ src/main/java/org/apache/giraph/benchmark/ src/main/java/org/apache/giraph/comm/ src/main/java/org/apache/giraph/examples/ src/main/java/org/apache/giraph/graph/ src/main/java/org/apache/giraph/grap...
Date Mon, 02 Jan 2012 18:52:51 GMT
Author: aching
Date: Mon Jan  2 18:52:50 2012
New Revision: 1226513

URL: http://svn.apache.org/viewvc?rev=1226513&view=rev
Log:
GIRAPH-116: Make EdgeListVertex the default vertex implementation, fix
bugs related to EdgeListVertex. (aching)


Added:
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/HashMapVertex.java
Modified:
    incubator/giraph/trunk/CHANGELOG
    incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PseudoRandomVertexInputFormat.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/BasicRPCCommunications.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/CommunicationsInterface.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/WorkerCommunications.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCheckpointVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCombinerVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleFailVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMsgVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMutateGraphVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleShortestPathsVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleSuperstepVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleVertexWithWorkerContext.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/VerifyMessage.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertexResolver.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/EdgeListVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/IntIntNullIntVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/LongDoubleFloatDoubleVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/MutableVertex.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/VertexResolver.java
    incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/partition/Partition.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestLongDoubleDoubleAdjacencyListVertexInputFormat.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestTextDoubleDoubleAdjacencyListVertexInputFormat.java
    incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java

Modified: incubator/giraph/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/CHANGELOG?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/CHANGELOG (original)
+++ incubator/giraph/trunk/CHANGELOG Mon Jan  2 18:52:50 2012
@@ -2,6 +2,9 @@ Giraph Change Log
 
 Release 0.70.0 - unreleased
 
+  GIRAPH-116: Make EdgeListVertex the default vertex implementation,
+  fix bugs related to EdgeListVertex. (aching)
+
   GIRAPH-115: Port of the HCC algorithm for identifying all connected
   components of a graph. (ssc via aching)
 

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PageRankBenchmark.java Mon Jan  2 18:52:50 2012
@@ -25,7 +25,7 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.cli.PosixParser;
 import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.GiraphJob;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.HashMapVertex;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.DoubleWritable;
 import org.apache.hadoop.io.LongWritable;
@@ -44,7 +44,7 @@ public class PageRankBenchmark implement
     /** How many supersteps to run */
     public static String SUPERSTEP_COUNT = "PageRankBenchmark.superstepCount";
 
-    public static class PageRankVertex extends Vertex<
+    public static class PageRankHashMapVertex extends HashMapVertex<
             LongWritable, DoubleWritable, DoubleWritable, DoubleWritable> {
         @Override
         public void compute(Iterator<DoubleWritable> msgIterator) {
@@ -163,8 +163,8 @@ public class PageRankBenchmark implement
         if (!cmd.hasOption('c') ||
                 (Integer.parseInt(cmd.getOptionValue('c')) == 0)) {
             System.out.println("Using " +
-                                PageRankVertex.class.getName());
-            job.setVertexClass(PageRankVertex.class);
+                                PageRankHashMapVertex.class.getName());
+            job.setVertexClass(PageRankHashMapVertex.class);
         } else {
             System.out.println("Using " +
                                 PageRankEdgeListVertex.class.getName());

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PseudoRandomVertexInputFormat.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PseudoRandomVertexInputFormat.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PseudoRandomVertexInputFormat.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/benchmark/PseudoRandomVertexInputFormat.java Mon Jan  2 18:52:50 2012
@@ -148,8 +148,8 @@ public class PseudoRandomVertexInputForm
         @Override
         public BasicVertex<LongWritable, DoubleWritable, DoubleWritable, M> getCurrentVertex()
                 throws IOException, InterruptedException {
-            BasicVertex<LongWritable, DoubleWritable, DoubleWritable, M> vertex =
-                BspUtils.createVertex(configuration);
+            BasicVertex<LongWritable, DoubleWritable, DoubleWritable, M>
+                vertex = BspUtils.createVertex(configuration);
             long vertexId = startingVertexId + verticesRead;
             // Seed on the vertex id to keep the vertex data the same when
             // on different number of workers, but other parameters are the
@@ -166,7 +166,8 @@ public class PseudoRandomVertexInputForm
                 } while (edges.containsKey(destVertexId));
                 edges.put(destVertexId, new DoubleWritable(rand.nextDouble()));
             }
-            vertex.initialize(new LongWritable(vertexId), vertexValue, edges, null);
+            vertex.initialize(
+                new LongWritable(vertexId), vertexValue, edges, null);
             ++verticesRead;
             if (LOG.isDebugEnabled()) {
                 LOG.debug("next: Return vertexId=" +

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/BasicRPCCommunications.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/BasicRPCCommunications.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/BasicRPCCommunications.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/BasicRPCCommunications.java Mon Jan  2 18:52:50 2012
@@ -708,7 +708,7 @@ end[HADOOP_FACEBOOK]*/
     }
 
     @Override
-    public final void addVertex(MutableVertex<I, V, E, M> vertex) {
+    public final void addVertex(BasicVertex<I, V, E, M> vertex) {
         if (LOG.isDebugEnabled()) {
             LOG.debug("addVertex: Adding vertex " + vertex);
         }
@@ -885,7 +885,7 @@ end[HADOOP_FACEBOOK]*/
     }
 
     @Override
-    public final void addVertexReq(MutableVertex<I, V, E, M> vertex)
+    public final void addVertexReq(BasicVertex<I, V, E, M> vertex)
             throws IOException {
         InetSocketAddress addr = getInetSocketAddress(vertex.getVertexId());
         if (LOG.isDebugEnabled()) {
@@ -1067,7 +1067,8 @@ end[HADOOP_FACEBOOK]*/
             VertexMutations<I, V, E, M> vertexMutations =
                 inVertexMutationsMap.get(vertexIndex);
             BasicVertex<I, V, E, M> vertex =
-                vertexResolver.resolve(originalVertex,
+                vertexResolver.resolve(vertexIndex,
+                                       originalVertex,
                                        vertexMutations,
                                        messages);
             if (LOG.isDebugEnabled()) {

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/CommunicationsInterface.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/CommunicationsInterface.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/CommunicationsInterface.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/CommunicationsInterface.java Mon Jan  2 18:52:50 2012
@@ -21,7 +21,7 @@ package org.apache.giraph.comm;
 import java.io.IOException;
 
 import org.apache.giraph.graph.Edge;
-import org.apache.giraph.graph.MutableVertex;
+import org.apache.giraph.graph.BasicVertex;
 /*if_not[HADOOP]
  else[HADOOP]*/
 import org.apache.giraph.hadoop.BspTokenSelector;
@@ -117,7 +117,7 @@ public interface CommunicationsInterface
      * @param vertex Vertex that will be added
      * @throws IOException
      */
-    void addVertex(MutableVertex<I, V, E, M> vertex) throws IOException;
+    void addVertex(BasicVertex<I, V, E, M> vertex) throws IOException;
 
     /**
      * Removed a remote vertex

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/WorkerCommunications.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/WorkerCommunications.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/WorkerCommunications.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/comm/WorkerCommunications.java Mon Jan  2 18:52:50 2012
@@ -20,7 +20,6 @@ package org.apache.giraph.comm;
 
 import org.apache.giraph.graph.BasicVertex;
 import org.apache.giraph.graph.Edge;
-import org.apache.giraph.graph.MutableVertex;
 import org.apache.giraph.graph.WorkerInfo;
 import org.apache.giraph.graph.partition.Partition;
 
@@ -92,7 +91,7 @@ public interface WorkerCommunications<I 
      * @param vertex Vertex to be added
      * @throws IOException
      */
-    void addVertexReq(MutableVertex<I, V, E, M> vertex) throws IOException;
+    void addVertexReq(BasicVertex<I, V, E, M> vertex) throws IOException;
 
     /**
      * Sends a request to the appropriate vertex range owner to remove a vertex

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCheckpointVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCheckpointVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCheckpointVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCheckpointVertex.java Mon Jan  2 18:52:50 2012
@@ -38,7 +38,7 @@ import java.util.Iterator;
  * can also test automated checkpoint restarts.
  */
 public class SimpleCheckpointVertex extends
-        Vertex<LongWritable, IntWritable, FloatWritable, FloatWritable>
+        EdgeListVertex<LongWritable, IntWritable, FloatWritable, FloatWritable>
         implements Tool {
     private static Logger LOG =
         Logger.getLogger(SimpleCheckpointVertex.class);
@@ -57,15 +57,15 @@ public class SimpleCheckpointVertex exte
 
     @Override
     public void compute(Iterator<FloatWritable> msgIterator) {
-    	SimpleCheckpointVertexWorkerContext workerContext = 
+    	SimpleCheckpointVertexWorkerContext workerContext =
     		(SimpleCheckpointVertexWorkerContext) getWorkerContext();
-    	
+
         LongSumAggregator sumAggregator = (LongSumAggregator)
             getAggregator(LongSumAggregator.class.getName());
-        
+
         boolean enableFault = workerContext.getEnableFault();
         int supersteps = workerContext.getSupersteps();
-        
+
         if (enableFault && (getSuperstep() == faultingSuperstep) &&
                 (getContext().getTaskAttemptID().getId() == 0) &&
                 (getVertexId().get() == faultingVertexId)) {
@@ -111,8 +111,8 @@ public class SimpleCheckpointVertex exte
             sendMsg(targetVertexId, new FloatWritable(edgeValue.get()));
         }
     }
-    
-    public static class SimpleCheckpointVertexWorkerContext 
+
+    public static class SimpleCheckpointVertexWorkerContext
             extends WorkerContext {
         /** User can access this after the application finishes if local */
         public static long finalSum;
@@ -124,7 +124,7 @@ public class SimpleCheckpointVertex exte
         private boolean enableFault = false;
 
 		@Override
-		public void preApplication() 
+		public void preApplication()
 		        throws InstantiationException, IllegalAccessException {
 		    registerAggregator(LongSumAggregator.class.getName(),
 					LongSumAggregator.class);
@@ -152,7 +152,7 @@ public class SimpleCheckpointVertex exte
 
 		@Override
 		public void postSuperstep() { }
-		
+
 		public int getSupersteps() {
 		    return this.supersteps;
 		}
@@ -211,7 +211,7 @@ public class SimpleCheckpointVertex exte
         int minWorkers = Integer.parseInt(cmd.getOptionValue('w'));
         int maxWorkers = Integer.parseInt(cmd.getOptionValue('w'));
         bspJob.setWorkerConfiguration(minWorkers, maxWorkers, 100.0f);
-        
+
         FileOutputFormat.setOutputPath(bspJob,
                                        new Path(cmd.getOptionValue('o')));
         boolean verbose = false;

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCombinerVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCombinerVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCombinerVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleCombinerVertex.java Mon Jan  2 18:52:50 2012
@@ -24,14 +24,14 @@ import org.apache.hadoop.io.FloatWritabl
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 
 /**
  * Test whether messages can go through a combiner.
- *
  */
 public class SimpleCombinerVertex extends
-    Vertex<LongWritable, IntWritable, FloatWritable, IntWritable> {
+        EdgeListVertex<LongWritable, IntWritable, FloatWritable, IntWritable> {
+    @Override
     public void compute(Iterator<IntWritable> msgIterator) {
         if (getVertexId().equals(new LongWritable(2))) {
             sendMsg(new LongWritable(1), new IntWritable(101));

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleFailVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleFailVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleFailVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleFailVertex.java Mon Jan  2 18:52:50 2012
@@ -18,7 +18,7 @@
 
 package org.apache.giraph.examples;
 
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.hadoop.io.DoubleWritable;
 import org.apache.hadoop.io.FloatWritable;
 import org.apache.hadoop.io.LongWritable;
@@ -29,7 +29,8 @@ import java.util.Iterator;
  * Vertex to allow unit testing of failure detection
  */
 public class SimpleFailVertex extends
-    Vertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> {
+        EdgeListVertex<LongWritable, DoubleWritable,
+        FloatWritable, DoubleWritable> {
 
     static long superstep = 0;
 

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMsgVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMsgVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMsgVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMsgVertex.java Mon Jan  2 18:52:50 2012
@@ -24,13 +24,13 @@ import org.apache.hadoop.io.FloatWritabl
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 
 /**
  * Test whether messages can be sent and received by vertices.
  */
 public class SimpleMsgVertex extends
-        Vertex<LongWritable, IntWritable, FloatWritable, IntWritable> {
+        EdgeListVertex<LongWritable, IntWritable, FloatWritable, IntWritable> {
     @Override
     public void compute(Iterator<IntWritable> msgIterator) {
         if (getVertexId().equals(new LongWritable(2))) {

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMutateGraphVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMutateGraphVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMutateGraphVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleMutateGraphVertex.java Mon Jan  2 18:52:50 2012
@@ -26,16 +26,16 @@ import org.apache.hadoop.io.FloatWritabl
 import org.apache.hadoop.io.LongWritable;
 import org.apache.log4j.Logger;
 
+import org.apache.giraph.graph.BasicVertex;
 import org.apache.giraph.graph.Edge;
-import org.apache.giraph.graph.Vertex;
-import org.apache.giraph.graph.MutableVertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.WorkerContext;
 
 /**
  * Vertex to allow unit testing of graph mutations.
  */
 public class SimpleMutateGraphVertex extends
-        Vertex<LongWritable, DoubleWritable,
+        EdgeListVertex<LongWritable, DoubleWritable,
         FloatWritable, DoubleWritable> {
     /** Maximum number of ranges for vertex ids */
     private long maxRanges = 100;
@@ -83,11 +83,11 @@ public class SimpleMutateGraphVertex ext
                     " on superstep " + getSuperstep());
             }
             // Create vertices that are sure not to exist (doubling vertices)
-            MutableVertex<LongWritable, DoubleWritable,
-                FloatWritable, DoubleWritable> vertex = instantiateVertex();
             LongWritable vertexIndex =
                 new LongWritable(rangeVertexIdStart(3) + getVertexId().get());
-            vertex.setVertexId(vertexIndex);
+            BasicVertex<LongWritable, DoubleWritable,
+                FloatWritable, DoubleWritable> vertex =
+                    instantiateVertex(vertexIndex, null, null, null);
             addVertexRequest(vertex);
             // Add edges to those remote vertices as well
             addEdgeRequest(vertexIndex,

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleShortestPathsVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleShortestPathsVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleShortestPathsVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleShortestPathsVertex.java Mon Jan  2 18:52:50 2012
@@ -23,7 +23,7 @@ import com.google.common.collect.Maps;
 import org.apache.giraph.graph.BasicVertex;
 import org.apache.giraph.graph.BspUtils;
 import org.apache.giraph.graph.GiraphJob;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.VertexReader;
 import org.apache.giraph.graph.VertexWriter;
 import org.apache.giraph.lib.TextVertexInputFormat;
@@ -56,8 +56,8 @@ import java.util.Map;
  * Demonstrates the basic Pregel shortest paths implementation.
  */
 public class SimpleShortestPathsVertex extends
-        Vertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable>
-        implements Tool {
+        EdgeListVertex<LongWritable, DoubleWritable,
+        FloatWritable, DoubleWritable> implements Tool {
     /** Configuration */
     private Configuration conf;
     /** Class logger */

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleSuperstepVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleSuperstepVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleSuperstepVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleSuperstepVertex.java Mon Jan  2 18:52:50 2012
@@ -21,7 +21,7 @@ package org.apache.giraph.examples;
 import com.google.common.collect.Maps;
 import org.apache.giraph.graph.BasicVertex;
 import org.apache.giraph.graph.BspUtils;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.VertexReader;
 import org.apache.giraph.graph.VertexWriter;
 import org.apache.giraph.lib.TextVertexOutputFormat;
@@ -44,7 +44,7 @@ import java.util.Map;
  * finishes.
  */
 public class SimpleSuperstepVertex extends
-        Vertex<LongWritable, IntWritable, FloatWritable, IntWritable> {
+        EdgeListVertex<LongWritable, IntWritable, FloatWritable, IntWritable> {
     @Override
     public void compute(Iterator<IntWritable> msgIterator) {
         if (getSuperstep() > 3) {

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleVertexWithWorkerContext.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleVertexWithWorkerContext.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleVertexWithWorkerContext.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/SimpleVertexWithWorkerContext.java Mon Jan  2 18:52:50 2012
@@ -24,7 +24,7 @@ import java.util.Iterator;
 
 import org.apache.giraph.examples.SimpleSuperstepVertex.SimpleSuperstepVertexInputFormat;
 import org.apache.giraph.graph.GiraphJob;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.WorkerContext;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
@@ -38,12 +38,12 @@ import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
 
 /**
- * Fully runnable example of how to 
+ * Fully runnable example of how to
  * emit worker data to HDFS during a graph
  * computation.
  */
 public class SimpleVertexWithWorkerContext extends
-        Vertex<LongWritable, IntWritable, FloatWritable, DoubleWritable> 
+        EdgeListVertex<LongWritable, IntWritable, FloatWritable, DoubleWritable>
         implements Tool {
 
     public static final String OUTPUTDIR = "svwwc.outputdir";
@@ -52,22 +52,22 @@ public class SimpleVertexWithWorkerConte
     @Override
     public void compute(Iterator<DoubleWritable> msgIterator)
             throws IOException {
-        
+
         long superstep = getSuperstep();
-        
+
         if (superstep < TESTLENGTH) {
-            EmitterWorkerContext emitter = 
+            EmitterWorkerContext emitter =
                     (EmitterWorkerContext) getWorkerContext();
-            emitter.emit("vertexId=" + getVertexId() + 
+            emitter.emit("vertexId=" + getVertexId() +
                          " superstep=" + superstep + "\n");
         } else {
             voteToHalt();
         }
     }
-    
+
     @SuppressWarnings("rawtypes")
 	public static class EmitterWorkerContext extends WorkerContext {
-        
+
         private static final String FILENAME = "emitter_";
         private DataOutputStream out;
 
@@ -75,7 +75,7 @@ public class SimpleVertexWithWorkerConte
         public void preApplication() {
             Context context = getContext();
             FileSystem fs;
-            
+
             try {
                 fs = FileSystem.get(context.getConfiguration());
 
@@ -83,23 +83,23 @@ public class SimpleVertexWithWorkerConte
                     .get(SimpleVertexWithWorkerContext.OUTPUTDIR);
                 if (p == null) {
                     throw new IllegalArgumentException(
-                        SimpleVertexWithWorkerContext.OUTPUTDIR + 
+                        SimpleVertexWithWorkerContext.OUTPUTDIR +
                         " undefined!");
                 }
-            
+
                 Path path = new Path(p);
                 if (!fs.exists(path)) {
-                    throw new IllegalArgumentException(path + 
+                    throw new IllegalArgumentException(path +
                             " doesn't exist");
                 }
 
-                Path outF = new Path(path, FILENAME + 
+                Path outF = new Path(path, FILENAME +
                         context.getTaskAttemptID());
                 if (fs.exists(outF)) {
-                    throw new IllegalArgumentException(outF + 
+                    throw new IllegalArgumentException(outF +
                             " aready exists");
                 }
-            
+
                 out = fs.create(outF);
             } catch (IOException e) {
                 throw new RuntimeException(
@@ -126,7 +126,7 @@ public class SimpleVertexWithWorkerConte
 
         @Override
         public void postSuperstep() { }
-        
+
         public void emit(String s) {
             try {
                 out.writeUTF(s);
@@ -158,7 +158,7 @@ public class SimpleVertexWithWorkerConte
             return -1;
         }
     }
-    
+
     public static void main(String[] args) throws Exception {
         System.exit(ToolRunner.run(new SimpleVertexWithWorkerContext(), args));
     }

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/VerifyMessage.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/VerifyMessage.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/VerifyMessage.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/examples/VerifyMessage.java Mon Jan  2 18:52:50 2012
@@ -75,7 +75,8 @@ public class VerifyMessage {
     }
 
     public static class VerifyMessageVertex extends
-            Vertex<LongWritable, IntWritable, FloatWritable, VerifiableMessage> {
+            EdgeListVertex<LongWritable, IntWritable, FloatWritable,
+            VerifiableMessage> {
         /** User can access this after the application finishes if local */
         public static long finalSum;
         /** Number of supersteps to run (6 by default) */

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertex.java Mon Jan  2 18:52:50 2012
@@ -26,7 +26,6 @@ import org.apache.hadoop.mapreduce.Mappe
 
 import java.io.IOException;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
  /**
@@ -48,8 +47,17 @@ public abstract class BasicVertex<I exte
     /** If true, do not do anymore computation on this vertex. */
     boolean halt = false;
 
+    /**
+     * This method must be called after instantiation of a vertex with BspUtils
+     * unless deserialization from readFields() is called.
+     *
+     * @param vertexId Will be the vertex id
+     * @param vertexValue Will be the vertex value
+     * @param edges A map of destination edge ids to edge values (can be null)
+     * @param messages Initial messages for this vertex (can be null)
+     */
     public abstract void initialize(
-        I vertexId, V vertexValue, Map<I, E> edges, List<M> messages);
+        I vertexId, V vertexValue, Map<I, E> edges, Iterable<M> messages);
 
     /**
      * Must be defined by user to do computation on a single Vertex.

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertexResolver.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertexResolver.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertexResolver.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BasicVertexResolver.java Mon Jan  2 18:52:50 2012
@@ -37,13 +37,16 @@ public interface BasicVertexResolver<
      * excluding the normal case (a vertex already exists and has zero or more
      * messages sent it to).
      *
+     * @param vertexId Vertex id (can be used for {@link BasicVertex}'s
+     *        initialize())
      * @param vertex Original vertex or null if none
      * @param vertexChanges Changes that happened to this vertex or null if none
      * @param messages messages received in the last superstep or null if none
      * @return Vertex to be returned, if null, and a vertex currently exists
      *         it will be removed
      */
-    BasicVertex<I, V, E, M> resolve(BasicVertex<I, V, E, M> vertex,
+    BasicVertex<I, V, E, M> resolve(I vertexId,
+                                    BasicVertex<I, V, E, M> vertex,
                                     VertexChanges<I, V, E, M> vertexChanges,
                                     Iterable<M> messages);
 

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/BspUtils.java Mon Jan  2 18:52:50 2012
@@ -151,7 +151,7 @@ public class BspUtils {
             getVertexOutputFormatClass(conf);
         return ReflectionUtils.newInstance(vertexOutputFormatClass, conf);
     }
-    
+
     /**
      * Get the user's subclassed {@link AggregatorWriter}.
      *
@@ -284,7 +284,7 @@ public class BspUtils {
 
 
     /**
-     * Get the user's subclassed Vertex.
+     * Get the user's subclassed {@link BasicVertex}
      *
      * @param conf Configuration to check
      * @return User's vertex class

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/EdgeListVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/EdgeListVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/EdgeListVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/EdgeListVertex.java Mon Jan  2 18:52:50 2012
@@ -63,12 +63,12 @@ public abstract class EdgeListVertex<I e
     /** Map of destination vertices and their edge values */
     private List<E> destEdgeValueList;
     /** List of incoming messages from the previous superstep */
-    private final List<M> msgList = Lists.newArrayList();
+    private List<M> msgList;
 
     @Override
     public void initialize(I vertexId, V vertexValue,
                            Map<I, E> edges,
-                           List<M> messages) {
+                           Iterable<M> messages) {
         if (vertexId != null) {
             setVertexId(vertexId);
         }
@@ -86,11 +86,14 @@ public abstract class EdgeListVertex<I e
             }
             sortedIndexList.clear();
         } else {
-            destEdgeIndexList = Lists.newArrayList();
-            destEdgeValueList = Lists.newArrayList();
+            destEdgeIndexList = Lists.newArrayListWithCapacity(0);
+            destEdgeValueList = Lists.newArrayListWithCapacity(0);
         }
-        if (messages != null && !messages.isEmpty()) {
-            msgList.addAll(messages);
+        if (messages != null) {
+            msgList = Lists.newArrayListWithCapacity(Iterables.size(messages));
+            Iterables.<M>addAll(msgList, messages);
+        } else {
+            msgList = Lists.newArrayListWithCapacity(0);
         }
     }
 
@@ -127,13 +130,13 @@ public abstract class EdgeListVertex<I e
 
     @Override
     public final boolean addEdge(I targetVertexId, E edgeValue) {
+        System.out.println("addEdge: " + targetVertexId + " " + edgeValue + " " + destEdgeIndexList);
         int pos = Collections.binarySearch(destEdgeIndexList,
                                            targetVertexId,
                                            new VertexIdComparator());
-        if (pos == destEdgeIndexList.size() ||
-                !destEdgeIndexList.get(pos).equals(targetVertexId)) {
-            destEdgeIndexList.add(pos, targetVertexId);
-            destEdgeValueList.add(pos, edgeValue);
+        if (pos < 0) {
+            destEdgeIndexList.add(-1 * (pos + 1), targetVertexId);
+            destEdgeValueList.add(-1 * (pos + 1), edgeValue);
             return true;
         } else {
             LOG.warn("addEdge: Vertex=" + vertexId +
@@ -173,8 +176,7 @@ public abstract class EdgeListVertex<I e
         int pos = Collections.binarySearch(destEdgeIndexList,
                 targetVertexId,
                 new VertexIdComparator());
-        if (pos == destEdgeIndexList.size() ||
-                !destEdgeIndexList.get(pos).equals(targetVertexId)) {
+        if (pos < 0) {
             return null;
         } else {
             return destEdgeValueList.get(pos);
@@ -186,8 +188,7 @@ public abstract class EdgeListVertex<I e
         int pos = Collections.binarySearch(destEdgeIndexList,
                 targetVertexId,
                 new VertexIdComparator());
-        if (pos == destEdgeIndexList.size() ||
-                !destEdgeIndexList.get(pos).equals(targetVertexId)) {
+        if (pos < 0) {
             return false;
         } else {
             return true;
@@ -215,8 +216,7 @@ public abstract class EdgeListVertex<I e
         int pos = Collections.binarySearch(destEdgeIndexList,
                 targetVertexId,
                 new VertexIdComparator());
-        if (pos == destEdgeIndexList.size() ||
-                !destEdgeIndexList.get(pos).equals(targetVertexId)) {
+        if (pos < 0) {
             return null;
         } else {
             destEdgeIndexList.remove(pos);
@@ -236,33 +236,6 @@ public abstract class EdgeListVertex<I e
     }
 
     @Override
-    public void addVertexRequest(MutableVertex<I, V, E, M> vertex)
-            throws IOException {
-        getGraphState().getWorkerCommunications().
-            addVertexReq(vertex);
-    }
-
-    @Override
-    public void removeVertexRequest(I vertexId) throws IOException {
-        getGraphState().getWorkerCommunications().
-            removeVertexReq(vertexId);
-    }
-
-    @Override
-    public void addEdgeRequest(I vertexIndex,
-                               Edge<I, E> edge) throws IOException {
-        getGraphState().getWorkerCommunications().
-            addEdgeReq(vertexIndex, edge);
-    }
-
-    @Override
-    public void removeEdgeRequest(I sourceVertexId,
-                                  I destVertexId) throws IOException {
-        getGraphState().getWorkerCommunications().
-            removeEdgeReq(sourceVertexId, destVertexId);
-    }
-
-    @Override
     final public void readFields(DataInput in) throws IOException {
         vertexId = BspUtils.<I>createVertexIndex(getConf());
         vertexId.readFields(in);
@@ -283,6 +256,7 @@ public abstract class EdgeListVertex<I e
             destEdgeValueList.add(edgeValue);
         }
         int msgListSize = in.readInt();
+        msgList = Lists.newArrayListWithCapacity(msgListSize);
         for (int i = 0; i < msgListSize; ++i) {
             M msg = BspUtils.<M>createMessageValue(getConf());
             msg.readFields(in);

Added: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/HashMapVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/HashMapVertex.java?rev=1226513&view=auto
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/HashMapVertex.java (added)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/HashMapVertex.java Mon Jan  2 18:52:50 2012
@@ -0,0 +1,243 @@
+/*
+ * 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.giraph.graph;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * User applications can subclass {@link HashMapVertex}, which stores
+ * the outbound edges in a HashMap, for efficient edge random-access.  Note
+ * that {@link EdgeListVertex} is much more memory efficient for static graphs.
+ * User applications which need to implement their own
+ * in-memory data structures should subclass {@link MutableVertex}.
+ *
+ * Package access will prevent users from accessing internal methods.
+ *
+ * @param <I> Vertex index value
+ * @param <V> Vertex value
+ * @param <E> Edge value
+ * @param <M> Message value
+ */
+@SuppressWarnings("rawtypes")
+public abstract class HashMapVertex<I extends WritableComparable,
+        V extends Writable, E extends Writable, M extends Writable>
+        extends MutableVertex<I, V, E, M> {
+    /** Class logger */
+    private static final Logger LOG = Logger.getLogger(HashMapVertex.class);
+    /** Vertex id */
+    private I vertexId = null;
+    /** Vertex value */
+    private V vertexValue = null;
+    /** Map of destination vertices and their edge values */
+    protected final Map<I, Edge<I, E>> destEdgeMap =
+        new HashMap<I, Edge<I, E>>();
+    /** List of incoming messages from the previous superstep */
+    private final List<M> msgList = Lists.newArrayList();
+
+    @Override
+    public void initialize(
+            I vertexId, V vertexValue, Map<I, E> edges, Iterable<M> messages) {
+        if (vertexId != null) {
+            setVertexId(vertexId);
+        }
+        if (vertexValue != null) {
+            setVertexValue(vertexValue);
+        }
+        if (edges != null && !edges.isEmpty()) {
+            for (Map.Entry<I, E> entry : edges.entrySet()) {
+                destEdgeMap.put(
+                    entry.getKey(),
+                    new Edge<I, E>(entry.getKey(), entry.getValue()));
+            }
+        }
+        if (messages != null) {
+            Iterables.<M>addAll(msgList, messages);
+        }
+    }
+
+    @Override
+    public final boolean addEdge(I targetVertexId, E edgeValue) {
+        if (destEdgeMap.put(
+                targetVertexId,
+                new Edge<I, E>(targetVertexId, edgeValue)) != null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("addEdge: Vertex=" + vertexId +
+                          ": already added an edge value for dest vertex id " +
+                          targetVertexId);
+            }
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public long getSuperstep() {
+        return getGraphState().getSuperstep();
+    }
+
+    @Override
+    public final void setVertexId(I vertexId) {
+        this.vertexId = vertexId;
+    }
+
+    @Override
+    public final I getVertexId() {
+        return vertexId;
+    }
+
+    @Override
+    public final V getVertexValue() {
+        return vertexValue;
+    }
+
+    @Override
+    public final void setVertexValue(V vertexValue) {
+        this.vertexValue = vertexValue;
+    }
+
+    @Override
+    public E getEdgeValue(I targetVertexId) {
+        Edge<I, E> edge = destEdgeMap.get(targetVertexId);
+        return edge != null ? edge.getEdgeValue() : null;
+    }
+
+    @Override
+    public boolean hasEdge(I targetVertexId) {
+        return destEdgeMap.containsKey(targetVertexId);
+    }
+
+    /**
+     * Get an iterator to the edges on this vertex.
+     *
+     * @return A <em>sorted</em> iterator, as defined by the sort-order
+     *         of the vertex ids
+     */
+    @Override
+    public Iterator<I> iterator() {
+        return destEdgeMap.keySet().iterator();
+    }
+
+    @Override
+    public int getNumOutEdges() {
+        return destEdgeMap.size();
+    }
+
+    @Override
+    public E removeEdge(I targetVertexId) {
+        Edge<I, E> edge = destEdgeMap.remove(targetVertexId);
+        if (edge != null) {
+            return edge.getEdgeValue();
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public final void sendMsgToAllEdges(M msg) {
+        if (msg == null) {
+            throw new IllegalArgumentException(
+                "sendMsgToAllEdges: Cannot send null message to all edges");
+        }
+        for (Edge<I, E> edge : destEdgeMap.values()) {
+            sendMsg(edge.getDestVertexId(), msg);
+        }
+    }
+
+    @Override
+    final public void readFields(DataInput in) throws IOException {
+        vertexId = BspUtils.<I>createVertexIndex(getConf());
+        vertexId.readFields(in);
+        boolean hasVertexValue = in.readBoolean();
+        if (hasVertexValue) {
+            vertexValue = BspUtils.<V>createVertexValue(getConf());
+            vertexValue.readFields(in);
+        }
+        long edgeMapSize = in.readLong();
+        for (long i = 0; i < edgeMapSize; ++i) {
+            Edge<I, E> edge = new Edge<I, E>();
+            edge.setConf(getConf());
+            edge.readFields(in);
+            addEdge(edge.getDestVertexId(), edge.getEdgeValue());
+        }
+        long msgListSize = in.readLong();
+        for (long i = 0; i < msgListSize; ++i) {
+            M msg = BspUtils.<M>createMessageValue(getConf());
+            msg.readFields(in);
+            msgList.add(msg);
+        }
+        halt = in.readBoolean();
+    }
+
+    @Override
+    final public void write(DataOutput out) throws IOException {
+        vertexId.write(out);
+        out.writeBoolean(vertexValue != null);
+        if (vertexValue != null) {
+            vertexValue.write(out);
+        }
+        out.writeLong(destEdgeMap.size());
+        for (Edge<I, E> edge : destEdgeMap.values()) {
+            edge.write(out);
+        }
+        out.writeLong(msgList.size());
+        for (M msg : msgList) {
+            msg.write(out);
+        }
+        out.writeBoolean(halt);
+    }
+
+    @Override
+    void setMessages(Iterable<M> messages) {
+        msgList.clear();
+        for (M message : messages) {
+            msgList.add(message);
+        }
+    }
+
+    @Override
+    public Iterable<M> getMessages() {
+        return Iterables.unmodifiableIterable(msgList);
+    }
+
+    @Override
+    void releaseResources() {
+        // Hint to GC to free the messages
+        msgList.clear();
+    }
+
+    @Override
+    public String toString() {
+        return "Vertex(id=" + getVertexId() + ",value=" + getVertexValue() +
+            ",#edges=" + destEdgeMap.size() + ")";
+    }
+}
+

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/IntIntNullIntVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/IntIntNullIntVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/IntIntNullIntVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/IntIntNullIntVertex.java Mon Jan  2 18:52:50 2012
@@ -27,7 +27,6 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -45,7 +44,8 @@ public abstract class IntIntNullIntVerte
 
     @Override
     public void initialize(IntWritable vertexId, IntWritable vertexValue,
-            Map<IntWritable, NullWritable> edges, List<IntWritable> messages) {
+            Map<IntWritable, NullWritable> edges,
+            Iterable<IntWritable> messages) {
         id = vertexId.get();
         value = vertexValue.get();
         this.neighbors = new int[edges.size()];
@@ -53,7 +53,7 @@ public abstract class IntIntNullIntVerte
         for (IntWritable neighbor : edges.keySet()) {
             this.neighbors[n++] = neighbor.get();
         }
-        this.messages = new int[messages.size()];
+        this.messages = new int[Iterables.size(messages)];
         n = 0;
         for (IntWritable message : messages) {
             this.messages[n++] = message.get();

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/LongDoubleFloatDoubleVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/LongDoubleFloatDoubleVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/LongDoubleFloatDoubleVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/LongDoubleFloatDoubleVertex.java Mon Jan  2 18:52:50 2012
@@ -32,7 +32,6 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 
 public abstract class LongDoubleFloatDoubleVertex extends
@@ -51,7 +50,7 @@ public abstract class LongDoubleFloatDou
     @Override
     public void initialize(LongWritable vertexIdW, DoubleWritable vertexValueW,
                            Map<LongWritable, FloatWritable> edgesW,
-                           List<DoubleWritable> messagesW) {
+                           Iterable<DoubleWritable> messagesW) {
         if (vertexIdW != null ) {
             vertexId = vertexIdW.get();
         }
@@ -201,34 +200,6 @@ public abstract class LongDoubleFloatDou
     }
 
     @Override
-    public void addVertexRequest(MutableVertex<LongWritable, DoubleWritable,
-            FloatWritable, DoubleWritable> vertex)
-            throws IOException {
-        getGraphState().getWorkerCommunications().addVertexReq(vertex);
-    }
-
-    @Override
-    public void removeVertexRequest(LongWritable vertexId) throws IOException {
-        getGraphState().getWorkerCommunications().removeVertexReq(vertexId);
-    }
-
-    @Override
-    public void addEdgeRequest(LongWritable vertexIndex,
-                               Edge<LongWritable, FloatWritable> edge)
-                               throws IOException {
-        getGraphState().getWorkerCommunications().addEdgeReq(vertexIndex,
-                                                             edge);
-    }
-
-    @Override
-    public void removeEdgeRequest(LongWritable sourceVertexId,
-                                  LongWritable destVertexId)
-                                  throws IOException {
-        getGraphState().getWorkerCommunications().removeEdgeReq(
-            sourceVertexId, destVertexId);
-    }
-
-    @Override
     final public void readFields(DataInput in) throws IOException {
         vertexId = in.readLong();
         vertexValue = in.readDouble();

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/MutableVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/MutableVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/MutableVertex.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/MutableVertex.java Mon Jan  2 18:52:50 2012
@@ -22,6 +22,7 @@ import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
 
 import java.io.IOException;
+import java.util.Map;
 
 /**
  * Interface used by VertexReader to set the properties of a new vertex
@@ -57,15 +58,18 @@ public abstract class MutableVertex<I ex
     public abstract E removeEdge(I targetVertexId);
 
     /**
-     * Create a vertex to add to the graph.
+     * Create a vertex to add to the graph.  Calls initialize() for the vertex
+     * as well.
      *
      * @return A new vertex for adding to the graph
      */
-    public MutableVertex<I, V, E, M> instantiateVertex() {
+    public BasicVertex<I, V, E, M> instantiateVertex(
+        I vertexId, V vertexValue, Map<I, E> edges, Iterable<M> messages) {
         MutableVertex<I, V, E, M> mutableVertex =
             (MutableVertex<I, V, E, M>) BspUtils
                .<I, V, E, M>createVertex(getContext().getConfiguration());
         mutableVertex.setGraphState(getGraphState());
+        mutableVertex.initialize(vertexId, vertexValue, edges, messages);
         return mutableVertex;
     }
 
@@ -75,10 +79,10 @@ public abstract class MutableVertex<I ex
      *
      * @param vertex User created vertex
      */
-    public void addVertexRequest(MutableVertex<I, V, E, M> vertex)
+    public void addVertexRequest(BasicVertex<I, V, E, M> vertex)
             throws IOException {
         getGraphState().getWorkerCommunications().
-        addVertexReq(vertex);
+            addVertexReq(vertex);
     }
 
     /**

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/VertexResolver.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/VertexResolver.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/VertexResolver.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/VertexResolver.java Mon Jan  2 18:52:50 2012
@@ -50,6 +50,7 @@ public class VertexResolver<I extends Wr
 
     @Override
     public BasicVertex<I, V, E, M> resolve(
+            I vertexId,
             BasicVertex<I, V, E, M> vertex,
             VertexChanges<I, V, E, M> vertexChanges,
             Iterable<M> messages) {
@@ -87,8 +88,10 @@ public class VertexResolver<I extends Wr
             if (vertex == null && messages != null
                     && !Iterables.isEmpty(messages)) {
                 vertex = instantiateVertex();
-                V vertexValue = BspUtils.<V>createVertexValue(getConf());
-                vertex.setVertexValue(vertexValue);
+                vertex.initialize(vertexId,
+                                  BspUtils.<V>createVertexValue(getConf()),
+                                  null,
+                                  messages);
             }
         } else {
             if ((vertexChanges != null) &&
@@ -105,7 +108,8 @@ public class VertexResolver<I extends Wr
                 (MutableVertex<I, V, E, M>) vertex;
             for (Edge<I, E> edge : vertexChanges.getAddedEdgeList()) {
                 edge.setConf(getConf());
-                mutableVertex.addEdge(edge.getDestVertexId(), edge.getEdgeValue());
+                mutableVertex.addEdge(edge.getDestVertexId(),
+                                      edge.getEdgeValue());
             }
         }
 
@@ -114,7 +118,8 @@ public class VertexResolver<I extends Wr
 
     @Override
     public BasicVertex<I, V, E, M> instantiateVertex() {
-        BasicVertex<I, V, E, M> vertex = BspUtils.<I,V,E,M>createVertex(getConf());
+        BasicVertex<I, V, E, M> vertex =
+            BspUtils.<I, V, E, M>createVertex(getConf());
         vertex.setGraphState(graphState);
         return vertex;
     }

Modified: incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/partition/Partition.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/partition/Partition.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/partition/Partition.java (original)
+++ incubator/giraph/trunk/src/main/java/org/apache/giraph/graph/partition/Partition.java Mon Jan  2 18:52:50 2012
@@ -27,7 +27,6 @@ import java.util.Map;
 
 import org.apache.giraph.graph.BasicVertex;
 import org.apache.giraph.graph.BspUtils;
-import org.apache.giraph.graph.Vertex;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
@@ -128,7 +127,7 @@ public class Partition<I extends Writabl
                 BspUtils.<I, V, E, M>createVertex(conf);
             vertex.readFields(input);
             if (vertexMap.put(vertex.getVertexId(),
-                              (Vertex<I, V, E, M>) vertex) != null) {
+                              (BasicVertex<I, V, E, M>) vertex) != null) {
                 throw new IllegalStateException(
                     "readFields: " + this +
                     " already has same id " + vertex);

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestBspBasic.java Mon Jan  2 18:52:50 2012
@@ -107,6 +107,7 @@ public class TestBspBasic extends BspCas
                            FloatWritable, IntWritable>();
         BasicVertex<LongWritable, IntWritable, FloatWritable, IntWritable> vertex =
             BspUtils.createVertex(job.getConfiguration());
+        vertex.initialize(null, null, null, null);
         System.out.println("testInstantiateVertex: Got vertex " + vertex +
                            ", graphState" + gs);
         VertexInputFormat<LongWritable, IntWritable, FloatWritable, IntWritable>
@@ -283,11 +284,11 @@ public class TestBspBasic extends BspCas
         job.setVertexInputFormatClass(SimplePageRankVertexInputFormat.class);
         assertTrue(job.run(true));
         if (getJobTracker() == null) {
-            double maxPageRank = 
+            double maxPageRank =
             	SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMax;
-            double minPageRank = 
+            double minPageRank =
             	SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMin;
-            long numVertices = 
+            long numVertices =
             	SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalSum;
             System.out.println("testBspPageRank: maxPageRank=" + maxPageRank +
                                " minPageRank=" + minPageRank +
@@ -336,7 +337,7 @@ public class TestBspBasic extends BspCas
             assertTrue(fileStatus.getLen() == fileStatus2.getLen());
         }
     }
-    
+
     /**
      * Run a sample BSP job locally and test PageRank with AggregatorWriter.
      *
@@ -357,17 +358,17 @@ public class TestBspBasic extends BspCas
         removeAndSetOutput(job, outputPath);
         assertTrue(job.run(true));
         if (getJobTracker() == null) {
-            double maxPageRank = 
+            double maxPageRank =
                 SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMax;
-            double minPageRank = 
+            double minPageRank =
                 SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalMin;
-            long numVertices = 
+            long numVertices =
                 SimplePageRankVertex.SimplePageRankVertexWorkerContext.finalSum;
             System.out.println("testBspPageRank: maxPageRank=" + maxPageRank +
                                " minPageRank=" + minPageRank +
                                " numVertices=" + numVertices);
             FileSystem fs = FileSystem.get(new Configuration());
-            FSDataInputStream input = 
+            FSDataInputStream input =
                 fs.open(new Path(SimpleAggregatorWriter.filename));
             int i, all;
             for (i = 0; ; i++) {
@@ -394,7 +395,7 @@ public class TestBspBasic extends BspCas
             input.close();
             // contained all supersteps
             assertTrue(i == SimplePageRankVertex.MAX_SUPERSTEPS+1 && all == 0);
-            remove(new Configuration(), 
+            remove(new Configuration(),
                    new Path(SimpleAggregatorWriter.filename));
         }
     }

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestJsonBase64Format.java Mon Jan  2 18:52:50 2012
@@ -65,7 +65,7 @@ public class TestJsonBase64Format extend
             throws IOException, InterruptedException, ClassNotFoundException {
         GiraphJob job = new GiraphJob(getCallingMethodName());
         setupConfiguration(job);
-        job.setVertexClass(PageRankBenchmark.PageRankVertex.class);
+        job.setVertexClass(PageRankBenchmark.PageRankEdgeListVertex.class);
         job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
         job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
         job.getConfiguration().setLong(
@@ -79,7 +79,7 @@ public class TestJsonBase64Format extend
 
         job = new GiraphJob(getCallingMethodName());
         setupConfiguration(job);
-        job.setVertexClass(PageRankBenchmark.PageRankVertex.class);
+        job.setVertexClass(PageRankBenchmark.PageRankEdgeListVertex.class);
         job.setVertexInputFormatClass(JsonBase64VertexInputFormat.class);
         job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
         job.getConfiguration().setInt(PageRankBenchmark.SUPERSTEP_COUNT, 3);
@@ -95,7 +95,7 @@ public class TestJsonBase64Format extend
 
         job = new GiraphJob(getCallingMethodName());
         setupConfiguration(job);
-        job.setVertexClass(PageRankBenchmark.PageRankVertex.class);
+        job.setVertexClass(PageRankBenchmark.PageRankEdgeListVertex.class);
         job.setVertexInputFormatClass(PseudoRandomVertexInputFormat.class);
         job.setVertexOutputFormatClass(JsonBase64VertexOutputFormat.class);
         job.getConfiguration().setLong(

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java Mon Jan  2 18:52:50 2012
@@ -26,8 +26,9 @@ import junit.framework.TestCase;
 
 import org.apache.giraph.examples.GeneratedVertexInputFormat;
 import org.apache.giraph.examples.SimpleSuperstepVertex.SimpleSuperstepVertexInputFormat;
+import org.apache.giraph.graph.BasicVertex;
 import org.apache.giraph.graph.GiraphJob;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.giraph.graph.VertexCombiner;
 import org.apache.giraph.graph.VertexInputFormat;
 import org.apache.giraph.graph.GraphMapper;
@@ -48,7 +49,8 @@ public class TestVertexTypes
      * Matches the {@link GeneratedVertexInputFormat}
      */
     private static class GeneratedVertexMatch extends
-            Vertex<LongWritable, IntWritable, FloatWritable, FloatWritable> {
+            EdgeListVertex<LongWritable, IntWritable, FloatWritable,
+            FloatWritable> {
         @Override
         public void compute(Iterator<FloatWritable> msgIterator)
                 throws IOException {
@@ -65,7 +67,8 @@ public class TestVertexTypes
      * Mismatches the {@link GeneratedVertexInputFormat}
      */
     private static class GeneratedVertexMismatch extends
-            Vertex<LongWritable, FloatWritable, FloatWritable, FloatWritable> {
+            EdgeListVertex<LongWritable, FloatWritable, FloatWritable,
+            FloatWritable> {
         @Override
         public void compute(Iterator<FloatWritable> msgIterator)
                 throws IOException {
@@ -107,7 +110,7 @@ public class TestVertexTypes
         Configuration conf = new Configuration();
         conf.setClass(GiraphJob.VERTEX_CLASS,
                       GeneratedVertexMatch.class,
-                      Vertex.class);
+                      BasicVertex.class);
         conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
                       SimpleSuperstepVertexInputFormat.class,
                       VertexInputFormat.class);
@@ -124,7 +127,7 @@ public class TestVertexTypes
         Configuration conf = new Configuration();
         conf.setClass(GiraphJob.VERTEX_CLASS,
                       DerivedVertexMatch.class,
-                      Vertex.class);
+                      BasicVertex.class);
         conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
                       SimpleSuperstepVertexInputFormat.class,
                       VertexInputFormat.class);
@@ -138,7 +141,7 @@ public class TestVertexTypes
         Configuration conf = new Configuration();
         conf.setClass(GiraphJob.VERTEX_CLASS,
                       DerivedVertexMatch.class,
-                      Vertex.class);
+                      BasicVertex.class);
         conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
                       SimpleSuperstepVertexInputFormat.class,
                       VertexInputFormat.class);
@@ -152,7 +155,7 @@ public class TestVertexTypes
         Configuration conf = new Configuration();
         conf.setClass(GiraphJob.VERTEX_CLASS,
                       GeneratedVertexMismatch.class,
-                      Vertex.class);
+                      BasicVertex.class);
         conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
                       SimpleSuperstepVertexInputFormat.class,
                       VertexInputFormat.class);
@@ -171,7 +174,7 @@ public class TestVertexTypes
         Configuration conf = new Configuration();
         conf.setClass(GiraphJob.VERTEX_CLASS,
                       GeneratedVertexMatch.class,
-                      Vertex.class);
+                      BasicVertex.class);
         conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
                       SimpleSuperstepVertexInputFormat.class,
                       VertexInputFormat.class);
@@ -193,7 +196,7 @@ public class TestVertexTypes
         Configuration conf = new Configuration();
         conf.setClass(GiraphJob.VERTEX_CLASS,
                       GeneratedVertexMatch.class,
-                      Vertex.class);
+                      BasicVertex.class);
         conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
                       JsonBase64VertexInputFormat.class,
                       VertexInputFormat.class);

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/examples/SimpleShortestPathVertexTest.java Mon Jan  2 18:52:50 2012
@@ -44,6 +44,7 @@ public class SimpleShortestPathVertexTes
     public void testOnShorterPathFound() throws Exception {
 
         SimpleShortestPathsVertex vertex = new SimpleShortestPathsVertex();
+        vertex.initialize(null, null, null, null);
         vertex.addEdge(new LongWritable(10L), new FloatWritable(2.5f));
         vertex.addEdge(new LongWritable(20L), new FloatWritable(0.5f));
 
@@ -72,6 +73,7 @@ public class SimpleShortestPathVertexTes
     public void testOnNoShorterPathFound() throws Exception {
 
         SimpleShortestPathsVertex vertex = new SimpleShortestPathsVertex();
+        vertex.initialize(null, null, null, null);
         vertex.addEdge(new LongWritable(10L), new FloatWritable(2.5f));
         vertex.addEdge(new LongWritable(20L), new FloatWritable(0.5f));
 

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/graph/TestEdgeListVertex.java Mon Jan  2 18:52:50 2012
@@ -87,7 +87,7 @@ public class TestEdgeListVertex extends 
     public void testEdges() {
         Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
         for (int i = 1000; i > 0; --i) {
-            edgeMap.put(new IntWritable(i), new DoubleWritable(i*2.0));
+            edgeMap.put(new IntWritable(i), new DoubleWritable(i * 2.0));
         }
         vertex.initialize(null, null, edgeMap, null);
         assertEquals(vertex.getNumOutEdges(), 1000);
@@ -103,10 +103,63 @@ public class TestEdgeListVertex extends 
         assertEquals(vertex.getNumOutEdges(), 999);
     }
 
+    public void testGetEdges() {
+        Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
+        for (int i = 1000; i > 0; --i) {
+            edgeMap.put(new IntWritable(i), new DoubleWritable(i * 3.0));
+        }
+        vertex.initialize(null, null, edgeMap, null);
+        assertEquals(vertex.getNumOutEdges(), 1000);
+        assertEquals(vertex.getEdgeValue(new IntWritable(600)),
+                     new DoubleWritable(600 * 3.0));
+        assertEquals(vertex.removeEdge(new IntWritable(600)),
+                     new DoubleWritable(600 * 3.0));
+        assertEquals(vertex.getNumOutEdges(), 999);
+        assertEquals(vertex.getEdgeValue(new IntWritable(500)),
+                     new DoubleWritable(500 * 3.0));
+        assertEquals(vertex.getEdgeValue(new IntWritable(700)),
+                     new DoubleWritable(700 * 3.0));
+    }
+
+    public void testAddRemoveEdges() {
+        Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
+        vertex.initialize(null, null, edgeMap, null);
+        assertEquals(vertex.getNumOutEdges(), 0);
+        assertTrue(vertex.addEdge(new IntWritable(2),
+                                  new DoubleWritable(2.0)));
+        assertEquals(vertex.getNumOutEdges(), 1);
+        assertEquals(vertex.getEdgeValue(new IntWritable(2)),
+                                         new DoubleWritable(2.0));
+        assertTrue(vertex.addEdge(new IntWritable(4),
+                                 new DoubleWritable(4.0)));
+        assertTrue(vertex.addEdge(new IntWritable(3),
+                                  new DoubleWritable(3.0)));
+        assertTrue(vertex.addEdge(new IntWritable(1),
+                                  new DoubleWritable(1.0)));
+        assertEquals(vertex.getNumOutEdges(), 4);
+        assertNull(vertex.getEdgeValue(new IntWritable(5)));
+        assertNull(vertex.getEdgeValue(new IntWritable(0)));
+        int i = 1;
+        for (IntWritable edgeDestId : vertex) {
+            assertEquals(i, edgeDestId.get());
+            assertEquals(i * 1.0d, vertex.getEdgeValue(edgeDestId).get());
+            ++i;
+        }
+        assertNotNull(vertex.removeEdge(new IntWritable(1)));
+        assertEquals(vertex.getNumOutEdges(), 3);
+        assertNotNull(vertex.removeEdge(new IntWritable(3)));
+        assertEquals(vertex.getNumOutEdges(), 2);
+        assertNotNull(vertex.removeEdge(new IntWritable(2)));
+        assertEquals(vertex.getNumOutEdges(), 1);
+        assertNotNull(vertex.removeEdge(new IntWritable(4)));
+        assertEquals(vertex.getNumOutEdges(), 0);
+    }
+
+
     public void testSerialize() {
         Map<IntWritable, DoubleWritable> edgeMap = Maps.newHashMap();
         for (int i = 1000; i > 0; --i) {
-            edgeMap.put(new IntWritable(i), new DoubleWritable(i*2.0));
+            edgeMap.put(new IntWritable(i), new DoubleWritable(i * 2.0));
         }
         List<LongWritable> messageList = Lists.newArrayList();
         messageList.add(new LongWritable(4));

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestLongDoubleDoubleAdjacencyListVertexInputFormat.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestLongDoubleDoubleAdjacencyListVertexInputFormat.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestLongDoubleDoubleAdjacencyListVertexInputFormat.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestLongDoubleDoubleAdjacencyListVertexInputFormat.java Mon Jan  2 18:52:50 2012
@@ -23,7 +23,7 @@ import org.apache.giraph.graph.BasicVert
 import org.apache.giraph.graph.Edge;
 import org.apache.giraph.graph.GiraphJob;
 import org.apache.giraph.graph.GraphState;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.DoubleWritable;
@@ -136,7 +136,8 @@ public class TestLongDoubleDoubleAdjacen
   }
 
   public static class DummyVertex
-      extends Vertex<LongWritable, DoubleWritable, DoubleWritable, BooleanWritable> {
+      extends EdgeListVertex<LongWritable, DoubleWritable,
+      DoubleWritable, BooleanWritable> {
     @Override
     public void compute(Iterator<BooleanWritable> msgIterator) throws IOException {
       // ignore

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestTextDoubleDoubleAdjacencyListVertexInputFormat.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestTextDoubleDoubleAdjacencyListVertexInputFormat.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestTextDoubleDoubleAdjacencyListVertexInputFormat.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/lib/TestTextDoubleDoubleAdjacencyListVertexInputFormat.java Mon Jan  2 18:52:50 2012
@@ -26,7 +26,7 @@ import org.apache.giraph.graph.BspUtils;
 import org.apache.giraph.graph.Edge;
 import org.apache.giraph.graph.GiraphJob;
 import org.apache.giraph.graph.GraphState;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.EdgeListVertex;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.BooleanWritable;
 import org.apache.hadoop.io.DoubleWritable;
@@ -212,7 +212,8 @@ public class TestTextDoubleDoubleAdjacen
   }
 
   public static class DummyVertex
-      extends Vertex<Text, DoubleWritable, DoubleWritable, BooleanWritable> {
+      extends EdgeListVertex<Text, DoubleWritable,
+      DoubleWritable, BooleanWritable> {
     @Override
     public void compute(Iterator<BooleanWritable> msgIterator) throws IOException {
       // ignore

Modified: incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java
URL: http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java?rev=1226513&r1=1226512&r2=1226513&view=diff
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java (original)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/utils/MockUtils.java Mon Jan  2 18:52:50 2012
@@ -20,7 +20,7 @@ package org.apache.giraph.utils;
 
 import org.apache.giraph.comm.WorkerCommunications;
 import org.apache.giraph.graph.GraphState;
-import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.BasicVertex;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
@@ -107,7 +107,7 @@ public class MockUtils {
     public static <I extends WritableComparable, V extends Writable,
             E extends Writable, M extends Writable>
             MockedEnvironment<I, V, E, M> prepareVertex(
-            Vertex<I, V, E, M> vertex, long superstep, I vertexId,
+            BasicVertex<I, V, E, M> vertex, long superstep, I vertexId,
             V vertexValue, boolean isHalted) throws Exception {
 
         MockedEnvironment<I, V, E, M>  env =



Mime
View raw message