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.VertexInputFormat;
22import org.apache.giraph.io.VertexReader;
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 VertexInputFormat} 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 <V> Vertex data46 * @param <E> Edge data47 */48publicclass WrappedVertexInputFormat<I extends WritableComparable,
49 V extends Writable, E extends Writable>
50extends VertexInputFormat<I, V, E> {
51/** {@link VertexInputFormat} which is wrapped */52private VertexInputFormat<I, V, E> originalInputFormat;
5354/**55 * Constructor56 *57 * @param vertexInputFormat Vertex input format to wrap58 */59publicWrappedVertexInputFormat(
60 VertexInputFormat<I, V, E> vertexInputFormat) {
61 originalInputFormat = vertexInputFormat;
62 }
6364 @Override
65publicvoid checkInputSpecs(Configuration conf) {
66 originalInputFormat.checkInputSpecs(getConf());
67 }
6869 @Override
70public List<InputSplit> getSplits(JobContext context,
71int minSplitCountHint) throws IOException, InterruptedException {
72return originalInputFormat.getSplits(
73 HadoopUtils.makeJobContext(getConf(), context),
74 minSplitCountHint);
75 }
7677 @Override
78public VertexReader<I, V, E> createVertexReader(InputSplit split,
79 TaskAttemptContext context) throws IOException {
80final VertexReader<I, V, E> vertexReader =
81 originalInputFormat.createVertexReader(split,
82 HadoopUtils.makeTaskAttemptContext(getConf(), context));
83returnnew WrappedVertexReader<I, V, E>(vertexReader, getConf());
84 }
8586 @Override
87publicvoid writeInputSplit(InputSplit inputSplit,
88 DataOutput dataOutput) throws IOException {
89 originalInputFormat.writeInputSplit(inputSplit, dataOutput);
90 }
9192 @Override
93public InputSplit readInputSplit(
94 DataInput dataInput) throws IOException, ClassNotFoundException {
95return originalInputFormat.readInputSplit(dataInput);
96 }
97 }