Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6cb919f39107ff4d6b5f950f2d5b7eefc8a048bb @chriseidhof committed Jul 5, 2011
38 pom.xml
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.example.maximumValue</groupId>
+ <artifactId>my-app</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>my-app</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.goldenorb</groupId>
+ <artifactId>core</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-core</artifactId>
+ <version>0.20.2</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
13 src/main/java/com/example/maximumValue/App.java
@@ -0,0 +1,13 @@
+package com.example.maximumValue;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
58 src/main/java/com/example/maximumValue/MaximumValueVertex.java
@@ -0,0 +1,58 @@
+package org.example.maximumValue;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.hadoop.io.IntWritable;
+import org.goldenorb.Edge;
+import org.goldenorb.Vertex;
+import org.goldenorb.types.message.IntMessage;
+
+public class MaximumValueVertex extends Vertex<IntWritable, IntWritable, IntMessage>{
+
+ int maxValue = 0;
+
+ public MaximumValueVertex(){
+ super(IntWritable.class, IntWritable.class, IntMessage.class);
+ }
+
+ public MaximumValueVertex(String _vertexID, IntWritable _value, List<Edge<IntWritable>> _edges) {
+ super(_vertexID, _value, _edges);
+ }
+
+ @Override
+ public void compute(Collection<IntMessage> messages) {
+
+ int _maxValue = 0;
+
+ for(IntMessage m: messages){
+
+ int msgValue = ((IntWritable)m.getMessageValue()).get();
+ if( msgValue > _maxValue ){
+ _maxValue = msgValue;
+ }
+ }
+
+ if(this.getValue().get() > _maxValue){
+ _maxValue = this.getValue().get();
+ }
+
+ if(_maxValue > maxValue){
+ maxValue = _maxValue;
+ for(Edge<IntWritable> e: getEdges()){
+ sendMessage(new IntMessage(e.getDestinationVertex(), new IntWritable(maxValue)));
+ }
+ }
+
+ this.voteToHalt();
+ }
+
+ public int getMaxValue(){
+ return maxValue;
+ }
+
+ @Override
+ public String toString(){
+ return "\"Value\":\"" + maxValue + "\"";
+ }
+}
27 src/main/java/com/example/maximumValue/MaximumValueVertexReader.java
@@ -0,0 +1,27 @@
+package org.example.maximumValue;
+
+import java.util.ArrayList;
+
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.Text;
+import org.goldenorb.Edge;
+import org.goldenorb.conf.OrbConfiguration;
+import org.goldenorb.io.input.VertexBuilder;
+
+public class MaximumValueVertexReader extends VertexBuilder<MaximumValueVertex,LongWritable,Text>{
+
+ @Override
+ public MaximumValueVertex buildVertex(LongWritable key, Text value) {
+ String[] values = value.toString().split("\t");
+ ArrayList<Edge<IntWritable>> edgeCollection = new ArrayList<Edge<IntWritable>>();
+ for(int i=2; i < values.length; i++){
+ Edge<IntWritable> edge = new Edge<IntWritable>(Integer.toString(Integer.parseInt(values[i].trim())), new IntWritable(0));
+ edgeCollection.add(edge);
+ }
+
+ MaximumValueVertex vertex = new MaximumValueVertex(Integer.toString(Integer.parseInt(values[0].trim())), new IntWritable(Integer.parseInt(values[1].trim())), edgeCollection);
+
+ return vertex;
+ }
+}
14 src/main/java/com/example/maximumValue/MaximumValueVertexWriter.java
@@ -0,0 +1,14 @@
+package org.example.maximumValue;
+
+import org.apache.hadoop.io.Text;
+import org.goldenorb.io.output.OrbContext;
+import org.goldenorb.io.output.VertexWriter;
+
+public class MaximumValueVertexWriter extends VertexWriter<MaximumValueVertex, Text, Text> {
+ @Override
+ public OrbContext<Text, Text> vertexWrite(MaximumValueVertex vertex) {
+ OrbContext<Text, Text> orbContext = new OrbContext<Text, Text>();
+ orbContext.write(new Text(vertex.getVertexID()), new Text(Integer.toString(vertex.getMaxValue())));
+ return orbContext;
+ }
+}
32 src/main/java/com/example/maximumValue/OrbMaximumValueJob.java
@@ -0,0 +1,32 @@
+package org.example.maximumValue;
+
+import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
+import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
+import org.goldenorb.OrbRunner;
+import org.goldenorb.conf.OrbConfiguration;
+import org.goldenorb.types.message.IntMessage;
+
+public class OrbMaximumValueJob extends OrbRunner{
+ public static void main(String[] args){
+ OrbMaximumValueJob omvj = new OrbMaximumValueJob();
+ omvj.startJob();
+ }
+
+ private void startJob(){
+ OrbConfiguration orbConf = new OrbConfiguration(true);
+ orbConf.setFileInputFormatClass(TextInputFormat.class);
+ orbConf.setFileOutputFormatClass(TextOutputFormat.class);
+ orbConf.setVertexClass(MaximumValueVertex.class);
+ orbConf.setMessageClass(IntMessage.class);
+ orbConf.setVertexInputFormatClass(MaximumValueVertexReader.class);
+ orbConf.setVertexOutputFormatClass(MaximumValueVertexWriter.class);
+ orbConf.setNumberOfMessageHandlers(10);
+ orbConf.setNumberOfVertexThreads(10);
+ orbConf.setNumberOfPartitionsPerMachine(3);
+ orbConf.setOrbRequestedPartitions(9);
+ orbConf.setFileInputPath("/path/to/input/data/");
+ orbConf.setFileOutputPath("/path/to/output/data/");
+ orbConf.setOrbClassPaths("/path/to/your/jar");
+ runJob(orbConf);
+ }
+}

0 comments on commit 6cb919f

Please sign in to comment.
Something went wrong with that request. Please try again.