This project has retired. For details please refer to its Attic page.
WrappedVertexInputFormat 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.VertexInputFormat;
22  import org.apache.giraph.io.VertexReader;
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 VertexInputFormat} 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 <V> Vertex data
46   * @param <E> Edge data
47   */
48  public class WrappedVertexInputFormat<I extends WritableComparable,
49      V extends Writable, E extends Writable>
50      extends VertexInputFormat<I, V, E> {
51    /** {@link VertexInputFormat} which is wrapped */
52    private VertexInputFormat<I, V, E> originalInputFormat;
53  
54    /**
55     * Constructor
56     *
57     * @param vertexInputFormat Vertex input format to wrap
58     */
59    public WrappedVertexInputFormat(
60        VertexInputFormat<I, V, E> vertexInputFormat) {
61      originalInputFormat = vertexInputFormat;
62    }
63  
64    @Override
65    public void checkInputSpecs(Configuration conf) {
66      originalInputFormat.checkInputSpecs(getConf());
67    }
68  
69    @Override
70    public List<InputSplit> getSplits(JobContext context,
71        int minSplitCountHint) throws IOException, InterruptedException {
72      return originalInputFormat.getSplits(
73          HadoopUtils.makeJobContext(getConf(), context),
74          minSplitCountHint);
75    }
76  
77    @Override
78    public VertexReader<I, V, E> createVertexReader(InputSplit split,
79        TaskAttemptContext context) throws IOException {
80      final VertexReader<I, V, E> vertexReader =
81          originalInputFormat.createVertexReader(split,
82              HadoopUtils.makeTaskAttemptContext(getConf(), context));
83      return new WrappedVertexReader<I, V, E>(vertexReader, getConf());
84    }
85  
86    @Override
87    public void writeInputSplit(InputSplit inputSplit,
88        DataOutput dataOutput) throws IOException {
89      originalInputFormat.writeInputSplit(inputSplit, dataOutput);
90    }
91  
92    @Override
93    public InputSplit readInputSplit(
94        DataInput dataInput) throws IOException, ClassNotFoundException {
95      return originalInputFormat.readInputSplit(dataInput);
96    }
97  }