This project has retired. For details please refer to its Attic page.
SupplierFromConf 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.block_app.framework.piece.messages;
19  
20  import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
21  import org.apache.giraph.factories.DefaultMessageValueFactory;
22  import org.apache.giraph.factories.MessageValueFactory;
23  import org.apache.giraph.function.Function;
24  import org.apache.giraph.writable.kryo.HadoopKryo;
25  import org.apache.hadoop.io.Writable;
26  
27  /**
28   * Supplier from configuration
29   * @param <T> Type of object returned
30   */
31  public interface SupplierFromConf<T>
32      extends Function<ImmutableClassesGiraphConfiguration, T> {
33  
34    /**
35     * Supplier from configuration, by copying given instance every time.
36     *
37     * @param <T> Type of object returned
38     */
39    public static class SupplierFromConfByCopy<T> implements SupplierFromConf<T> {
40      private final T value;
41  
42      public SupplierFromConfByCopy(T value) {
43        this.value = value;
44      }
45  
46      @Override
47      public T apply(ImmutableClassesGiraphConfiguration conf) {
48        return HadoopKryo.createCopy(value);
49      }
50    }
51  
52    /**
53     * Supplier from configuration returning DefaultMessageValueFactory instances.
54     *
55     * @param <M> Message type
56     */
57    public static class DefaultMessageFactorySupplierFromConf<M extends Writable>
58        implements SupplierFromConf<MessageValueFactory<M>> {
59      private final Class<M> messageClass;
60  
61      public DefaultMessageFactorySupplierFromConf(Class<M> messageClass) {
62        this.messageClass = messageClass;
63      }
64  
65      @Override
66      public MessageValueFactory<M> apply(
67          ImmutableClassesGiraphConfiguration conf) {
68        return new DefaultMessageValueFactory<>(messageClass, conf);
69      }
70    }
71  }