This project has retired. For details please refer to its Attic page.
VertexReader xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.io;
20  
21  import java.io.IOException;
22  
23  import org.apache.giraph.graph.Vertex;
24  import org.apache.giraph.worker.WorkerAggregatorDelegator;
25  import org.apache.hadoop.io.Writable;
26  import org.apache.hadoop.io.WritableComparable;
27  import org.apache.hadoop.mapreduce.InputSplit;
28  import org.apache.hadoop.mapreduce.TaskAttemptContext;
29  
30  /**
31   * Analogous to Hadoop's RecordReader for vertices.  Will read the
32   * vertices from an input split.
33   *
34   * @param <I> Vertex id
35   * @param <V> Vertex data
36   * @param <E> Edge data
37   */
38  @SuppressWarnings("rawtypes")
39  public abstract class VertexReader<I extends WritableComparable,
40      V extends Writable, E extends Writable> extends
41      WorkerAggregatorDelegator<I, V, E> {
42    /**
43     * Use the input split and context to setup reading the vertices.
44     * Guaranteed to be called prior to any other function.
45     *
46     * @param inputSplit Input split to be used for reading vertices.
47     * @param context Context from the task.
48     * @throws IOException
49     * @throws InterruptedException
50     */
51    public abstract void initialize(InputSplit inputSplit,
52                                    TaskAttemptContext context)
53      throws IOException, InterruptedException;
54  
55    /**
56     *
57     * @return false iff there are no more vertices
58     * @throws IOException
59     * @throws InterruptedException
60     */
61    public abstract boolean nextVertex() throws IOException,
62        InterruptedException;
63  
64    /**
65     * Get the current vertex.
66     *
67     * @return the current vertex which has been read.
68     *         nextVertex() should be called first.
69     * @throws IOException
70     * @throws InterruptedException
71     */
72    public abstract Vertex<I, V, E> getCurrentVertex()
73      throws IOException, InterruptedException;
74  
75    /**
76     * Close this {@link VertexReader} to future operations.
77     *
78     * @throws IOException
79     */
80    public abstract void close() throws IOException;
81  
82    /**
83     * How much of the input has the {@link VertexReader} consumed i.e.
84     * has been processed by?
85     *
86     * @return Progress from <code>0.0</code> to <code>1.0</code>.
87     * @throws IOException
88     * @throws InterruptedException
89     */
90    public abstract float getProgress() throws IOException, InterruptedException;
91  }