私はJavaとEclipseの両方の初心者です。Giraph プログラムを作成するために Eclipse を準備する方法を知りたいですか? Giraph をセットアップしましたが、動作しています。Giraph で Eclipse から書かれたプログラムを実行する方法はありますか?
ありがとうございました
はい、Hadoop クラスターなしで単一の Java アプリケーションから Giraph を実行することは可能です。
メインクラスは次のようになります。
public class GiraphHelloWorld extends BasicComputation<IntWritable, IntWritable, NullWritable, NullWritable> {
@Override
public void compute(Vertex<IntWritable, IntWritable, NullWritable> vertex,
Iterable<NullWritable> messages) {
System.out.print("Hello world from : " + vertex.getId().toString()
+ " friends are:");
for (Edge<IntWritable, NullWritable> e : vertex.getEdges()) {
System.out.print(" " + e.getTargetVertexId());
}
System.out.println("");
vertex.voteToHalt();
}
public static void main(String[] args) throws Exception {
System.exit(ToolRunner.run(new GiraphRunner(), args));
}
}
スターター クラスは次のようになります。
public class TestGiraphApp {
final static String[] graphSeed = new String[] { "seed\t0" };
@Test
public void testNumberOfVertices() throws Exception {
GiraphConfiguration conf = new GiraphConfiguration();
conf.setComputationClass(GiraphHelloWorld.class);
conf.setVertexInputFormatClass(IntIntNullTextInputFormat.class);
conf.setVertexOutputFormatClass(AdjacencyListTextVertexOutputFormat.class);
Iterable<String> results = InternalVertexRunner.run(conf, graphSeed);
}
}
pom.xml
ファイルには Giraph と Hadoop が含まれている必要があります。
<dependency>
<groupId>org.apache.giraph</groupId>
<artifactId>giraph-core</artifactId>
version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
この例は、Practical Graph Analytics with Apache Giraph bookのソース コードに基づいています。