Search in sources :

Example 1 with Edge

use of org.goldenorb.Edge in project goldenorb by jzachr.

the class OutboundVertexThread method testOutBoundVertexQueue.

@Test
public void testOutBoundVertexQueue() throws Exception {
    // OutboundVertexQueue settings
    int numberOfPartitions = 100;
    // max number of Vertices to be sent by a Thread
    int numOfVerticesToSendPerThread = 10500;
    // max number of Vertices to trigger a send operation by the queue
    int numOfVerticesPerBlock = 1000;
    int partitionId = 1;
    Class<? extends Vertex<?, ?, ?>> vertexClass = TestVertex.class;
    Map<Integer, OrbPartitionCommunicationProtocol> orbClients = new HashMap<Integer, OrbPartitionCommunicationProtocol>();
    for (int i = 0; i < numberOfPartitions; i++) {
        orbClients.put(new Integer(i), infoCollector);
    }
    OutboundVertexQueue ovq = new OutboundVertexQueue(numberOfPartitions, numOfVerticesPerBlock, orbClients, vertexClass, partitionId);
    // initialize the Threads and pass them their test Vertices
    CountDownLatch startLatch = new CountDownLatch(1);
    CountDownLatch everyoneDoneLatch = new CountDownLatch(numberOfPartitions);
    for (int i = 0; i < numberOfPartitions; i++) {
        Vertices vrts = new Vertices(vertexClass);
        for (int p = 0; p < numOfVerticesToSendPerThread; p++) {
            String vertexID = "vertex " + p;
            IntWritable vertexValue = new IntWritable(p);
            List<Edge<IntWritable>> edgesList = new ArrayList<Edge<IntWritable>>();
            TestVertex vrt = new TestVertex(vertexID, vertexValue, edgesList);
            vrts.add(vrt);
        }
        OutboundVertexThread obmThread = new OutboundVertexThread(vrts, ovq, startLatch, everyoneDoneLatch);
        // initialize a Thread
        obmThread.start();
    }
    // start all Threads simultaneously
    startLatch.countDown();
    // wait until all Threads are done
    everyoneDoneLatch.await();
    ovq.sendRemainingVertices();
    System.out.println(infoCollector.vList.size());
    assertThat(ovq, notNullValue());
    assertTrue(infoCollector.vList.size() == (numberOfPartitions * numOfVerticesToSendPerThread));
}
Also used : OrbPartitionCommunicationProtocol(org.goldenorb.OrbPartitionCommunicationProtocol) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Vertices(org.goldenorb.Vertices) Edge(org.goldenorb.Edge) IntWritable(org.apache.hadoop.io.IntWritable) Test(org.junit.Test)

Example 2 with Edge

use of org.goldenorb.Edge in project goldenorb by jzachr.

the class SingleSourceShortestPathReader method buildVertex.

@Override
public SingleSourceShortestPathVertex buildVertex(LongWritable key, Text value) {
    String[] values = value.toString().split("\t");
    ArrayList<Edge<IntWritable>> edgeCollection = new ArrayList<Edge<IntWritable>>();
    for (int i = 1; i < values.length; i++) {
        String[] split = values[i].split(":");
        Edge<IntWritable> edge = new Edge<IntWritable>(Integer.toString(Integer.parseInt(split[0].trim())), new IntWritable(Integer.parseInt(split[1])));
        edgeCollection.add(edge);
    }
    PathWritable emptyPathWritable = new PathWritable();
    SingleSourceShortestPathVertex vertex = new SingleSourceShortestPathVertex(Integer.toString(Integer.parseInt(values[0].trim())), emptyPathWritable, edgeCollection);
    return vertex;
}
Also used : ArrayList(java.util.ArrayList) Edge(org.goldenorb.Edge) IntWritable(org.apache.hadoop.io.IntWritable)

Example 3 with Edge

use of org.goldenorb.Edge in project goldenorb by jzachr.

the class MaximumValueVertexReader method buildVertex.

@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);
    //    System.out.println(vertex);
    return vertex;
}
Also used : ArrayList(java.util.ArrayList) Edge(org.goldenorb.Edge) IntWritable(org.apache.hadoop.io.IntWritable)

Aggregations

ArrayList (java.util.ArrayList)3 IntWritable (org.apache.hadoop.io.IntWritable)3 Edge (org.goldenorb.Edge)3 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 OrbPartitionCommunicationProtocol (org.goldenorb.OrbPartitionCommunicationProtocol)1 Vertices (org.goldenorb.Vertices)1 Test (org.junit.Test)1