This project has retired. For details please refer to its Attic page.
EdgeInputSplitsCallableFactory 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.worker;
20  
21  import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22  import org.apache.giraph.graph.VertexEdgeCount;
23  import org.apache.giraph.io.EdgeInputFormat;
24  import org.apache.giraph.utils.CallableFactory;
25  import org.apache.hadoop.io.Writable;
26  import org.apache.hadoop.io.WritableComparable;
27  import org.apache.hadoop.mapreduce.Mapper;
28  
29  /**
30   * Factory for {@link EdgeInputSplitsCallable}s.
31   *
32   * @param <I> Vertex id
33   * @param <V> Vertex value
34   * @param <E> Edge value
35   */
36  public class EdgeInputSplitsCallableFactory<I extends WritableComparable,
37      V extends Writable, E extends Writable>
38      implements CallableFactory<VertexEdgeCount> {
39    /** Edge input format */
40    private final EdgeInputFormat<I, E> edgeInputFormat;
41    /** Mapper context. */
42    private final Mapper<?, ?, ?, ?>.Context context;
43    /** Configuration. */
44    private final ImmutableClassesGiraphConfiguration<I, V, E> configuration;
45    /** {@link BspServiceWorker} we're running on. */
46    private final BspServiceWorker<I, V, E> bspServiceWorker;
47    /** Handler for input splits */
48    private final WorkerInputSplitsHandler splitsHandler;
49  
50    /**
51     * Constructor.
52     *
53     * @param edgeInputFormat Edge input format
54     * @param context Mapper context
55     * @param configuration Configuration
56     * @param bspServiceWorker Calling {@link BspServiceWorker}
57     * @param splitsHandler Handler for input splits
58     */
59    public EdgeInputSplitsCallableFactory(
60        EdgeInputFormat<I, E> edgeInputFormat,
61        Mapper<?, ?, ?, ?>.Context context,
62        ImmutableClassesGiraphConfiguration<I, V, E> configuration,
63        BspServiceWorker<I, V, E> bspServiceWorker,
64        WorkerInputSplitsHandler splitsHandler) {
65      this.edgeInputFormat = edgeInputFormat;
66      this.context = context;
67      this.configuration = configuration;
68      this.bspServiceWorker = bspServiceWorker;
69      this.splitsHandler = splitsHandler;
70    }
71  
72    @Override
73    public InputSplitsCallable<I, V, E> newCallable(int threadId) {
74      return new EdgeInputSplitsCallable<I, V, E>(
75          edgeInputFormat,
76          context,
77          configuration,
78          bspServiceWorker,
79          splitsHandler);
80    }
81  }