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.MappingInputFormat;
22import org.apache.giraph.io.MappingReader;
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 org.apache.giraph.io.VertexInputFormat} to make40 * sure proper configuration parameters are passed around, that user can set41 * parameters in configuration and they will be available in other methods42 * related to this format.43 *44 * @param <I> vertexId type45 * @param <V> vertexValue type46 * @param <E> edgeValue type47 * @param <B> mappingTarget type48 */49publicclass WrappedMappingInputFormat<I extends WritableComparable,
50 V extends Writable, E extends Writable, B extends Writable>
51extends MappingInputFormat<I, V, E, B> {
52/** originalInputFormat to wrap over */53private MappingInputFormat<I, V, E, B> originalInputFormat;
5455/**56 * Constructor57 *58 * @param mappingInputFormat original mappingInputFormat59 */60publicWrappedMappingInputFormat(
61 MappingInputFormat<I, V, E, B> mappingInputFormat) {
62 originalInputFormat = mappingInputFormat;
63 }
6465 @Override
66publicvoid checkInputSpecs(Configuration conf) {
67 originalInputFormat.checkInputSpecs(conf);
68 }
6970 @Override
71public List<InputSplit> getSplits(JobContext context, int minSplitCountHint)
72throws IOException, InterruptedException {
73return originalInputFormat.getSplits(
74 HadoopUtils.makeJobContext(getConf(), context),
75 minSplitCountHint);
76 }
7778 @Override
79public MappingReader<I, V, E, B> createMappingReader(InputSplit split,
80 TaskAttemptContext context) throws IOException {
81final MappingReader<I, V, E, B> mappingReader = originalInputFormat
82 .createMappingReader(split,
83 HadoopUtils.makeTaskAttemptContext(getConf(), context));
84returnnew WrappedMappingReader<>(mappingReader, getConf());
85 }
868788 @Override
89publicvoid writeInputSplit(InputSplit inputSplit,
90 DataOutput dataOutput) throws IOException {
91 originalInputFormat.writeInputSplit(inputSplit, dataOutput);
92 }
9394 @Override
95public InputSplit readInputSplit(
96 DataInput dataInput) throws IOException, ClassNotFoundException {
97return originalInputFormat.readInputSplit(dataInput);
98 }
99 }