当前位置: 首页 > 工具软件 > Apache Hama > 使用案例 >

apache-hama-kcore

李博达
2023-12-01
package org.apache.hamaDemo;import java.io.IOException;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.LongWritable;import org.apache.hadoop.io.Text;import org.apache.hama.HamaConfiguration;import org.apache.hama.bsp.TextInputFormat;import org.apache.hama.bsp.TextOutputFormat;import org.apache.hama.examples.KCore;import org.apache.hama.graph.GraphJob;import org.apache.hama.ml.kcore.KCoreMessage;import org.apache.hama.ml.kcore.KCoreVertex;import org.apache.hama.ml.kcore.KCoreVertexReader;import org.apache.hama.ml.kcore.KCoreVertexWriter;public class DemoKcore {public static GraphJob createKCore(HamaConfiguration hamaConfiguration) throws IOException{GraphJob graphJob = new GraphJob(hamaConfiguration, KCore.class);//设置图形的点、边graphJob.setVertexClass(KCoreVertex.class);graphJob.setVertexIDClass(LongWritable.class);graphJob.setEdgeValueClass(LongWritable.class);graphJob.setVertexValueClass(KCoreMessage.class);//设置输入路径graphJob.setInputPath(new Path("/home/workspace/input/core.txt"));graphJob.setVertexInputReaderClass(KCoreVertexReader.class);graphJob.setInputFormat(TextInputFormat.class);graphJob.setInputKeyClass(LongWritable.class);graphJob.setInputValueClass(Text.class);//设置输出路径graphJob.setOutputPath(new Path("/home/workspace/output"));graphJob.setOutputFormat(TextOutputFormat.class);graphJob.setOutputKeyClass(LongWritable.class);graphJob.setOutputValueClass(IntWritable.class);graphJob.setVertexOutputWriterClass(KCoreVertexWriter.class);return graphJob;}public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { HamaConfiguration hamaconf = new HamaConfiguration(); GraphJob graphJob = createKCore(hamaconf); long startTime =System.currentTimeMillis(); if (graphJob.waitForCompletion(true)) { System.out.println("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); }}}
 类似资料: