This project has retired. For details please refer to its Attic page.
MappingReader 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.mapping.MappingEntry;
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   * Will read the mapping from an input split.
32   *
33   * @param <I> vertexId type
34   * @param <V> vertexValue type
35   * @param <E> edgeValue type
36   * @param <B> mappingTarget type
37   */
38  public abstract class MappingReader<I extends WritableComparable,
39      V extends Writable, E extends Writable, B extends Writable>
40      extends WorkerAggregatorDelegator<I, V, E> {
41    /**
42     * Use the input split and context to setup reading the vertices.
43     * Guaranteed to be called prior to any other function.
44     *
45     * @param inputSplit Input split to be used for reading vertices.
46     * @param context Context from the task.
47     * @throws java.io.IOException
48     * @throws InterruptedException
49     */
50    public abstract void initialize(InputSplit inputSplit,
51      TaskAttemptContext context)
52      throws IOException, InterruptedException;
53  
54    /**
55     *
56     * @return false iff there are no more vertices
57     * @throws IOException
58     * @throws InterruptedException
59     */
60    public abstract boolean nextEntry() throws IOException,
61      InterruptedException;
62  
63  
64    /**
65     * Get the current entry.
66     *
67     * @return the current entry which has been read.
68     *         nextVEntry() should be called first.
69     * @throws IOException
70     * @throws InterruptedException
71     */
72    public abstract MappingEntry<I, B> getCurrentEntry()
73      throws IOException, InterruptedException;
74  
75  
76    /**
77     * Close this {@link MappingReader} to future operations.
78     *
79     * @throws IOException
80     */
81    public abstract void close() throws IOException;
82  
83    /**
84     * How much of the input has the {@link VertexReader} consumed i.e.
85     * has been processed by?
86     *
87     * @return Progress from <code>0.0</code> to <code>1.0</code>.
88     * @throws IOException
89     * @throws InterruptedException
90     */
91    public abstract float getProgress() throws IOException, InterruptedException;
92  }