This project has retired. For details please refer to its Attic page.
WrappedEdgeInputFormat 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.internal;
20  
21  import org.apache.giraph.io.EdgeInputFormat;
22  import org.apache.giraph.io.EdgeReader;
23  import org.apache.giraph.job.HadoopUtils;
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.io.Writable;
26  import org.apache.hadoop.io.WritableComparable;
27  import org.apache.hadoop.mapreduce.InputSplit;
28  import org.apache.hadoop.mapreduce.JobContext;
29  import org.apache.hadoop.mapreduce.TaskAttemptContext;
30  
31  import java.io.DataInput;
32  import java.io.DataOutput;
33  import java.io.IOException;
34  import java.util.List;
35  
36  /**
37   * For internal use only.
38   *
39   * Wraps user set {@link EdgeInputFormat} to make sure proper configuration
40   * parameters are passed around, that user can set parameters in
41   * configuration and they will be available in other methods related to this
42   * format.
43   *
44   * @param <I> Vertex id
45   * @param <E> Edge data
46   */
47  public class WrappedEdgeInputFormat<I extends WritableComparable,
48      E extends Writable> extends EdgeInputFormat<I, E> {
49    /** {@link EdgeInputFormat} which is wrapped */
50    private EdgeInputFormat<I, E> originalInputFormat;
51  
52    /**
53     * Constructor
54     *
55     * @param edgeInputFormat Edge input format to wrap
56     */
57    public WrappedEdgeInputFormat(
58        EdgeInputFormat<I, E> edgeInputFormat) {
59      originalInputFormat = edgeInputFormat;
60    }
61  
62    @Override
63    public void checkInputSpecs(Configuration conf) {
64      originalInputFormat.checkInputSpecs(getConf());
65    }
66  
67    @Override
68    public List<InputSplit> getSplits(JobContext context,
69        int minSplitCountHint) throws IOException, InterruptedException {
70      return originalInputFormat.getSplits(
71          HadoopUtils.makeJobContext(getConf(), context),
72          minSplitCountHint);
73    }
74  
75    @Override
76    public 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));
81      return new WrappedEdgeReader<I, E>(edgeReader, getConf());
82    }
83  
84    @Override
85    public void writeInputSplit(InputSplit inputSplit,
86        DataOutput dataOutput) throws IOException {
87      originalInputFormat.writeInputSplit(inputSplit, dataOutput);
88    }
89  
90    @Override
91    public InputSplit readInputSplit(
92        DataInput dataInput) throws IOException, ClassNotFoundException {
93      return originalInputFormat.readInputSplit(dataInput);
94    }
95  }