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.io.internal;
2021import org.apache.giraph.io.EdgeInputFormat;
22import org.apache.giraph.io.EdgeReader;
23import org.apache.giraph.job.HadoopUtils;
24import org.apache.hadoop.conf.Configuration;
25import org.apache.hadoop.io.Writable;
26import org.apache.hadoop.io.WritableComparable;
27import org.apache.hadoop.mapreduce.InputSplit;
28import org.apache.hadoop.mapreduce.JobContext;
29import org.apache.hadoop.mapreduce.TaskAttemptContext;
3031import java.io.DataInput;
32import java.io.DataOutput;
33import java.io.IOException;
34import java.util.List;
3536/**37 * For internal use only.38 *39 * Wraps user set {@link EdgeInputFormat} to make sure proper configuration40 * parameters are passed around, that user can set parameters in41 * configuration and they will be available in other methods related to this42 * format.43 *44 * @param <I> Vertex id45 * @param <E> Edge data46 */47publicclass WrappedEdgeInputFormat<I extends WritableComparable,
48 E extends Writable> extends EdgeInputFormat<I, E> {
49/** {@link EdgeInputFormat} which is wrapped */50private EdgeInputFormat<I, E> originalInputFormat;
5152/**53 * Constructor54 *55 * @param edgeInputFormat Edge input format to wrap56 */57publicWrappedEdgeInputFormat(
58 EdgeInputFormat<I, E> edgeInputFormat) {
59 originalInputFormat = edgeInputFormat;
60 }
6162 @Override
63publicvoid checkInputSpecs(Configuration conf) {
64 originalInputFormat.checkInputSpecs(getConf());
65 }
6667 @Override
68public List<InputSplit> getSplits(JobContext context,
69int minSplitCountHint) throws IOException, InterruptedException {
70return originalInputFormat.getSplits(
71 HadoopUtils.makeJobContext(getConf(), context),
72 minSplitCountHint);
73 }
7475 @Override
76public EdgeReader<I, E> createEdgeReader(InputSplit split,
77 TaskAttemptContext context) throws IOException {
78 EdgeReader<I, E> edgeReader =
79 originalInputFormat.createEdgeReader(split,
80 HadoopUtils.makeTaskAttemptContext(getConf(), context));
81returnnew WrappedEdgeReader<I, E>(edgeReader, getConf());
82 }
8384 @Override
85publicvoid writeInputSplit(InputSplit inputSplit,
86 DataOutput dataOutput) throws IOException {
87 originalInputFormat.writeInputSplit(inputSplit, dataOutput);
88 }
8990 @Override
91public InputSplit readInputSplit(
92 DataInput dataInput) throws IOException, ClassNotFoundException {
93return originalInputFormat.readInputSplit(dataInput);
94 }
95 }