1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.examples;
2021import java.io.IOException;
22import org.apache.giraph.bsp.BspInputSplit;
23import org.apache.giraph.conf.LongConfOption;
24import org.apache.giraph.io.EdgeReader;
25import org.apache.hadoop.io.Writable;
26import org.apache.hadoop.io.WritableComparable;
27import org.apache.hadoop.mapreduce.InputSplit;
28import org.apache.hadoop.mapreduce.TaskAttemptContext;
2930/**31 * Used by GeneratedEdgeInputFormat32 * to read some generated data33 *34 * @param <I> Vertex index value35 * @param <E> Edge value36 */37 @SuppressWarnings("rawtypes")
38publicabstractclass GeneratedEdgeReader<
39 I extends WritableComparable,
40 E extends Writable>
41extends EdgeReader<I, E> {
42/** Default edges produced by this reader */43publicstaticfinalLongConfOption DEFAULT_READER_EDGES =
44newLongConfOption("GeneratedEdgeReader.reader_edges", 10,
45"Default edges produced by this reader");
46/** Records read so far */47protectedlong recordsRead = 0;
48/** Total records to read (on this split alone) */49protectedlong totalRecords = 0;
50/** The input split from initialize(). */51protectedBspInputSplit inputSplit = null;
5253/**54 * Default constructor for reflection.55 */56publicGeneratedEdgeReader() {
57 }
5859 @Override
60publicfinalvoid initialize(InputSplit inputSplit,
61 TaskAttemptContext context) throws IOException {
62 totalRecords = DEFAULT_READER_EDGES.get(getConf());
63this.inputSplit = (BspInputSplit) inputSplit;
64 }
6566 @Override
67publicvoid close() throws IOException {
68 }
6970 @Override
71publicfinalfloat getProgress() throws IOException {
72return recordsRead * 100.0f / totalRecords;
73 }
74 }