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;
2021import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable;
22import org.apache.hadoop.conf.Configuration;
23import org.apache.hadoop.io.Text;
24import org.apache.hadoop.io.Writable;
25import org.apache.hadoop.io.WritableComparable;
26import org.apache.hadoop.mapreduce.InputSplit;
27import org.apache.hadoop.mapreduce.JobContext;
28import org.apache.hadoop.util.ReflectionUtils;
2930import java.io.DataInput;
31import java.io.DataOutput;
32import java.io.IOException;
33import java.util.List;
3435/**36 * Common interface for {@link VertexInputFormat} and {@link EdgeInputFormat}.37 *38 * @param <I> Vertex id39 * @param <V> Vertex data40 * @param <E> Edge data41 */42publicabstractclass GiraphInputFormat<I extends WritableComparable,
43 V extends Writable, E extends Writable> extends44 DefaultImmutableClassesGiraphConfigurable<I, V, E> {
45/**46 * Check that input is valid.47 *48 * @param conf Configuration49 */50publicabstractvoid checkInputSpecs(Configuration conf);
5152/**53 * Get the list of input splits for the format.54 *55 * @param context The job context56 * @param minSplitCountHint Minimum number of splits to create (hint)57 * @return The list of input splits58 * @throws IOException59 * @throws InterruptedException60 */61publicabstract List<InputSplit> getSplits(JobContext context,
62int minSplitCountHint) throws IOException, InterruptedException;
6364/**65 * Write input split info to DataOutput.66 *67 * @param inputSplit InputSplit68 * @param dataOutput DataOutput69 */70publicvoid writeInputSplit(InputSplit inputSplit,
71 DataOutput dataOutput) throws IOException {
72 Text.writeString(dataOutput, inputSplit.getClass().getName());
73 ((Writable) inputSplit).write(dataOutput);
74 }
7576/**77 * Read input split info from DataInput.78 *79 * @param dataInput DataInput80 * @return InputSplit81 */82public InputSplit readInputSplit(DataInput dataInput) throws IOException,
83 ClassNotFoundException {
84 String inputSplitClass = Text.readString(dataInput);
85 InputSplit inputSplit = (InputSplit) ReflectionUtils.newInstance(
86 getConf().getClassByName(inputSplitClass), getConf());
87 ((Writable) inputSplit).readFields(dataInput);
88return inputSplit;
89 }
90 }