This project has retired. For details please refer to its Attic page.
ValueFactories 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  package org.apache.giraph.factories;
19  
20  import static org.apache.giraph.conf.GiraphConstants.EDGE_VALUE_FACTORY_CLASS;
21  import static org.apache.giraph.conf.GiraphConstants.VERTEX_ID_FACTORY_CLASS;
22  import static org.apache.giraph.conf.GiraphConstants.VERTEX_VALUE_FACTORY_CLASS;
23  
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.io.Writable;
26  import org.apache.hadoop.io.WritableComparable;
27  
28  /**
29   * Holder for factories to create user types.
30   *
31   * Note that we don't store the {@link MessageValueFactory} here because they
32   * reference types which may change at a given superstep. Instead we create them
33   * as necessary so that they get the latest information.
34   *
35   * @param <I> Vertex id
36   * @param <V> Vertex data
37   * @param <E> Edge data
38   */
39  public class ValueFactories<I extends WritableComparable,
40      V extends Writable, E extends Writable> {
41    /** Vertex ID factory. */
42    private final VertexIdFactory<I> vertexIdFactory;
43    /** Vertex value factory. */
44    private final VertexValueFactory<V> vertexValueFactory;
45    /** Edge value factory. */
46    private final EdgeValueFactory<E> edgeValueFactory;
47  
48    /**
49     * Constructor reading from Configuration
50     *
51     * @param conf Configuration to read from
52     */
53    public ValueFactories(Configuration conf) {
54      vertexIdFactory = VERTEX_ID_FACTORY_CLASS.newInstance(conf);
55      vertexValueFactory = VERTEX_VALUE_FACTORY_CLASS.newInstance(conf);
56      edgeValueFactory = EDGE_VALUE_FACTORY_CLASS.newInstance(conf);
57    }
58  
59    public EdgeValueFactory<E> getEdgeValueFactory() {
60      return edgeValueFactory;
61    }
62  
63    public VertexIdFactory<I> getVertexIdFactory() {
64      return vertexIdFactory;
65    }
66  
67    public VertexValueFactory<V> getVertexValueFactory() {
68      return vertexValueFactory;
69    }
70  }