Index: graph/src/main/java/org/apache/hama/graph/GraphJobMessage.java =================================================================== --- graph/src/main/java/org/apache/hama/graph/GraphJobMessage.java (revision 1442026) +++ graph/src/main/java/org/apache/hama/graph/GraphJobMessage.java (working copy) @@ -26,6 +26,7 @@ import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.MapWritable; import org.apache.hadoop.io.Writable; +import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.util.ReflectionUtils; /** @@ -33,7 +34,8 @@ * real message (vertex ID and value). It can be extended by adding flags, for * example for a graph repair call. */ -public final class GraphJobMessage implements Writable { +public final class GraphJobMessage implements Writable, + WritableComparable { public static final int MAP_FLAG = 0x01; public static final int VERTEX_FLAG = 0x02; @@ -217,4 +219,9 @@ + "]"; } + @Override + public int compareTo(GraphJobMessage that) { + return vertexId.toString().compareTo(that.getVertexId().toString()); + } + } Index: graph/src/test/java/org/apache/hama/graph/TestGraphJobMessage.java =================================================================== --- graph/src/test/java/org/apache/hama/graph/TestGraphJobMessage.java (revision 0) +++ graph/src/test/java/org/apache/hama/graph/TestGraphJobMessage.java (working copy) @@ -0,0 +1,54 @@ +/** + * 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.hama.graph; + +import java.util.PriorityQueue; + +import junit.framework.TestCase; + +import org.apache.hadoop.io.IntWritable; +import org.apache.hadoop.io.Text; + +public class TestGraphJobMessage extends TestCase { + + public void testCompare() throws Exception { + GraphJobMessage msg1 = new GraphJobMessage(new Text("1"), new Text( + "message")); + GraphJobMessage msg2 = new GraphJobMessage(new Text("2"), new Text( + "message")); + + msg1 = new GraphJobMessage(new IntWritable(123), new Text("message1")); + msg2 = new GraphJobMessage(new IntWritable(321), new Text("message1")); + GraphJobMessage msg3 = new GraphJobMessage(new IntWritable(123), new Text( + "message1")); + GraphJobMessage msg4 = new GraphJobMessage(new IntWritable(123), new Text( + "message2")); + + PriorityQueue queue = new PriorityQueue(); + queue.add(msg2); + queue.add(msg4); + queue.add(msg1); + queue.add(msg3); + + while (queue.size() != 0) { + System.out.println(queue.remove()); + } + + } + +}