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 org.apache.giraph.bsp.BspInputSplit;
22import org.apache.giraph.conf.BooleanConfOption;
23import org.apache.giraph.conf.LongConfOption;
24import org.apache.giraph.io.VertexReader;
25import org.apache.hadoop.io.Writable;
26import org.apache.hadoop.io.WritableComparable;
27import org.apache.hadoop.mapreduce.InputSplit;
28import org.apache.hadoop.mapreduce.TaskAttemptContext;
2930import java.io.IOException;
3132/**33 * Used by GeneratedVertexInputFormat to read some generated data34 *35 * @param <I> Vertex index value36 * @param <V> Vertex value37 * @param <E> Edge value38 */39 @SuppressWarnings("rawtypes")
40publicabstractclass GeneratedVertexReader<
41 I extends WritableComparable, V extends Writable,
42 E extends Writable>
43extends VertexReader<I, V, E> {
44/** Vertices produced by this reader */45publicstaticfinalLongConfOption READER_VERTICES =
46newLongConfOption("GeneratedVertexReader.reader_vertices", 10,
47"Vertices produced by this reader");
48/** Reverse the order of the vertices? */49publicstaticfinalBooleanConfOption REVERSE_ID_ORDER =
50newBooleanConfOption("GeneratedVertexReader.reverseIdOrder", false,
51"Reverse the order of the vertices?");
52/** Records read so far */53protectedlong recordsRead = 0;
54/** Total records to read (on this split alone) */55protectedlong totalRecords = 0;
56/** The input split from initialize(). */57protectedBspInputSplit inputSplit = null;
58/** Reverse the id order? */59protectedboolean reverseIdOrder;
6061/**62 * Default constructor for reflection.63 */64publicGeneratedVertexReader() {
65 }
6667 @Override
68publicfinalvoid initialize(InputSplit inputSplit,
69 TaskAttemptContext context) throws IOException {
70 totalRecords = GeneratedVertexReader.READER_VERTICES.get(getConf());
71 reverseIdOrder = GeneratedVertexReader.REVERSE_ID_ORDER.get(getConf());
72this.inputSplit = (BspInputSplit) inputSplit;
73 }
7475 @Override
76publicvoid close() throws IOException {
77 }
7879 @Override
80publicfinalfloat getProgress() throws IOException {
81return recordsRead * 100.0f / totalRecords;
82 }
83 }