
Here's Hama version Single Shortest Path algorithm, it's the same as described in Google's Pregel paper:
public static class ShortestPathVertex extends Vertex<IntegerMessage> { public ShortestPathVertex() { super(IntegerMessage.class); this.setValue(Integer.MAX_VALUE); } public boolean isStartVertex() { String startVertex = getConf().get(START_VERTEX); return (this.getVertexID().equals(startVertex)) ? true : false; } @Override public void compute(Iterator<IntegerMessage> messages) throws IOException { int minDist = isStartVertex() ? 0 : Integer.MAX_VALUE; while (messages.hasNext()) { IntegerMessage msg = messages.next(); if (msg.getData() < minDist) { minDist = msg.getData(); } } if (minDist < (Integer) this.getValue()) { this.setValue(minDist); for (Edge e : this.getOutEdges()) { sendMessage(e.getTarget(), new IntegerMessage(e.getName(), minDist + e.getCost())); } } } }