This project has retired. For details please refer to its Attic page.
GiraphInputFormat xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.io;
20  
21  import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable;
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.io.Text;
24  import org.apache.hadoop.io.Writable;
25  import org.apache.hadoop.io.WritableComparable;
26  import org.apache.hadoop.mapreduce.InputSplit;
27  import org.apache.hadoop.mapreduce.JobContext;
28  import org.apache.hadoop.util.ReflectionUtils;
29  
30  import java.io.DataInput;
31  import java.io.DataOutput;
32  import java.io.IOException;
33  import java.util.List;
34  
35  /**
36   * Common interface for {@link VertexInputFormat} and {@link EdgeInputFormat}.
37   *
38   * @param <I> Vertex id
39   * @param <V> Vertex data
40   * @param <E> Edge data
41   */
42  public abstract class GiraphInputFormat<I extends WritableComparable,
43      V extends Writable, E extends Writable> extends
44      DefaultImmutableClassesGiraphConfigurable<I, V, E> {
45    /**
46     * Check that input is valid.
47     *
48     * @param conf Configuration
49     */
50    public abstract void checkInputSpecs(Configuration conf);
51  
52    /**
53     * Get the list of input splits for the format.
54     *
55     * @param context The job context
56     * @param minSplitCountHint Minimum number of splits to create (hint)
57     * @return The list of input splits
58     * @throws IOException
59     * @throws InterruptedException
60     */
61    public abstract List<InputSplit> getSplits(JobContext context,
62        int minSplitCountHint) throws IOException, InterruptedException;
63  
64    /**
65     * Write input split info to DataOutput.
66     *
67     * @param inputSplit InputSplit
68     * @param dataOutput DataOutput
69     */
70    public void writeInputSplit(InputSplit inputSplit,
71        DataOutput dataOutput) throws IOException {
72      Text.writeString(dataOutput, inputSplit.getClass().getName());
73      ((Writable) inputSplit).write(dataOutput);
74    }
75  
76    /**
77     * Read input split info from DataInput.
78     *
79     * @param dataInput DataInput
80     * @return InputSplit
81     */
82    public 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);
88      return inputSplit;
89    }
90  }