Exemplo n.º 1
0
    @Override
    public Vertex<VLongWritable, DoubleWritable, FloatWritable, DoubleWritable> getCurrentVertex()
        throws IOException {
      Vertex<VLongWritable, DoubleWritable, FloatWritable, DoubleWritable> vertex =
          BspUtils.createVertex(configuration);

      VLongWritable vertexId =
          new VLongWritable(inputSplit.getSplitIndex() * totalRecords + recordsRead);
      DoubleWritable vertexValue = new DoubleWritable(vertexId.get() * 10d);
      long destVertexId = (vertexId.get() + 1) % (inputSplit.getNumSplits() * totalRecords);
      float edgeValue = vertexId.get() * 100f;
      edges.put(new VLongWritable(destVertexId), new FloatWritable(edgeValue));
      vertex.initialize(vertexId, vertexValue, edges, null);
      ++recordsRead;
      if (LOG.getLevel() == Level.FINE) {
        LOG.fine(
            "next: Return vertexId="
                + vertex.getVertexId().get()
                + ", vertexValue="
                + vertex.getVertexValue()
                + ", destinationId="
                + destVertexId
                + ", edgeValue="
                + edgeValue);
      }
      return vertex;
    }
  @SuppressWarnings("unchecked")
  @Override
  public Vertex<VLongWritable, VLongWritable, FloatWritable, VLongWritable> getCurrentVertex()
      throws IOException, InterruptedException {
    used = 0;
    if (vertex == null) vertex = (Vertex) BspUtils.createVertex(getContext().getConfiguration());
    vertex.getMsgList().clear();
    vertex.getEdges().clear();

    vertex.reset();
    Text line = getRecordReader().getCurrentValue();
    String[] fields = line.toString().split(separator);

    if (fields.length > 0) {
      /** set the src vertex id */
      long src = Long.parseLong(fields[0]);
      vertexId.set(src);
      vertex.setVertexId(vertexId);
      long dest = -1L;

      /** set up edges */
      for (int i = 1; i < fields.length; i++) {
        dest = Long.parseLong(fields[i]);
        VLongWritable destId = allocate();
        destId.set(dest);
        vertex.addEdge(destId, null);
      }
    }
    // vertex.sortEdges();
    return vertex;
  }
Exemplo n.º 3
0
 @Override
 public void writeVertex(Vertex<VLongWritable, DoubleWritable, FloatWritable, ?> vertex)
     throws IOException, InterruptedException {
   getRecordWriter()
       .write(
           new Text(vertex.getVertexId().toString()),
           new Text(vertex.getVertexValue().toString()));
 }
  @SuppressWarnings("unchecked")
  @Override
  public Vertex<VLongWritable, Text, FloatWritable, DoubleWritable> getCurrentVertex()
      throws IOException, InterruptedException {
    if (vertex == null) {
      vertex = BspUtils.createVertex(getContext().getConfiguration());
    }
    vertex.getMsgList().clear();
    vertex.getEdges().clear();

    vertex.reset();

    /** set the src vertex id */
    vertexId.set(currentId++);
    vertex.setVertexId(vertexId);

    /** set the vertex value */
    vertex.setVertexValue(new Text("aaa"));
    return vertex;
  }