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.bsp;
2021import java.io.IOException;
2223import org.apache.hadoop.mapreduce.InputSplit;
24import org.apache.hadoop.mapreduce.RecordReader;
25import org.apache.hadoop.mapreduce.TaskAttemptContext;
26import org.apache.hadoop.io.Text;
2728/**29 * Only returns a single key-value pair so that the map() can run.30 */31classBspRecordReaderextends RecordReader<Text, Text> {
32/** Singular key object */33privatestaticfinal Text ONLY_KEY = new Text("only key");
34/** Single value object */35privatestaticfinal Text ONLY_VALUE = new Text("only value");
3637/** Has the one record been seen? */38privateboolean seenRecord = false;
3940 @Override
41publicvoid close() throws IOException {
42return;
43 }
4445 @Override
46publicfloat getProgress() throws IOException {
47return seenRecord ? 1f : 0f;
48 }
4950 @Override
51public Text getCurrentKey() throws IOException, InterruptedException {
52return ONLY_KEY;
53 }
5455 @Override
56public Text getCurrentValue() throws IOException, InterruptedException {
57return ONLY_VALUE;
58 }
5960 @Override
61publicvoid initialize(InputSplit inputSplit, TaskAttemptContext context)
62throws IOException, InterruptedException {
63 }
6465 @Override
66publicboolean nextKeyValue() throws IOException, InterruptedException {
67if (!seenRecord) {
68 seenRecord = true;
69returntrue;
70 }
71return false;
72 }
73 }