Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
EdgeReader |
|
| 1.0;1 |
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.edge.Edge; | |
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 org.apache.giraph.bsp.BspRecordReader for edges. | |
32 | * Will read the edges from an input split. | |
33 | * | |
34 | * @param <I> Vertex id | |
35 | * @param <E> Edge data | |
36 | */ | |
37 | @SuppressWarnings("rawtypes") | |
38 | 0 | public abstract class EdgeReader<I extends WritableComparable, |
39 | E extends Writable> extends WorkerAggregatorDelegator< | |
40 | I, Writable, E> { | |
41 | ||
42 | /** | |
43 | * Use the input split and context to setup reading the edges. | |
44 | * Guaranteed to be called prior to any other function. | |
45 | * | |
46 | * @param inputSplit Input split to be used for reading edges. | |
47 | * @param context Context from the task. | |
48 | * @throws java.io.IOException | |
49 | * @throws InterruptedException | |
50 | */ | |
51 | public abstract void initialize(InputSplit inputSplit, | |
52 | TaskAttemptContext context) | |
53 | throws IOException, InterruptedException; | |
54 | ||
55 | /** | |
56 | * Read the next edge. | |
57 | * | |
58 | * @return false iff there are no more edges | |
59 | * @throws IOException | |
60 | * @throws InterruptedException | |
61 | */ | |
62 | public abstract boolean nextEdge() throws IOException, InterruptedException; | |
63 | ||
64 | /** | |
65 | * Get the current edge source id. | |
66 | * | |
67 | * @return Current edge source id which has been read. | |
68 | * nextEdge() should be called first. | |
69 | * @throws IOException | |
70 | * @throws InterruptedException | |
71 | */ | |
72 | public abstract I getCurrentSourceId() | |
73 | throws IOException, InterruptedException; | |
74 | ||
75 | /** | |
76 | * Get the current edge. | |
77 | * | |
78 | * @return the current edge which has been read. | |
79 | * nextEdge() should be called first. | |
80 | * @throws IOException | |
81 | * @throws InterruptedException | |
82 | */ | |
83 | public abstract Edge<I, E> getCurrentEdge() | |
84 | throws IOException, InterruptedException; | |
85 | ||
86 | /** | |
87 | * Close this {@link EdgeReader} to future operations. | |
88 | * | |
89 | * @throws IOException | |
90 | */ | |
91 | public abstract void close() throws IOException; | |
92 | ||
93 | /** | |
94 | * How much of the input has the {@link EdgeReader} consumed i.e. | |
95 | * has been processed by? | |
96 | * | |
97 | * @return Progress from <code>0.0</code> to <code>1.0</code>. | |
98 | * @throws IOException | |
99 | * @throws InterruptedException | |
100 | */ | |
101 | public abstract float getProgress() throws IOException, InterruptedException; | |
102 | } |