1. 程式人生 > >類中新增日誌列印

類中新增日誌列印

 利用log4j

package org.apache.giraph.examples;

import java.io.IOException;
import org.apache.giraph.edge.Edge;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.log4j.Logger;

public class InlinkCountComputation extends BasicComputation<IntWritable, IntWritable,
NullWritable, IntWritable>{
	  private static final Logger LOG = Logger.getLogger(InlinkCountComputation.class);
	
	  @Override
	  public void compute(Vertex<IntWritable, IntWritable, NullWritable> vertex,
	      Iterable<IntWritable> messages) throws IOException {
		  if(getSuperstep() == 0) {
			  vertex.setValue(new IntWritable(0));
			  for (Edge<IntWritable, NullWritable> edge : vertex
						.getEdges()) {
				  sendMessage(edge.getTargetVertexId(),new IntWritable(1));
			  }
		  } else {
			  for (IntWritable message : messages) { 
				  vertex.setValue( new IntWritable(vertex.getValue().get() + message.get()));
			  }
			  vertex.voteToHalt();
		  }
	  }
}