1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.giraph.block_app.framework.piece.messages;
1920import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
21import org.apache.giraph.factories.DefaultMessageValueFactory;
22import org.apache.giraph.factories.MessageValueFactory;
23import org.apache.giraph.function.Function;
24import org.apache.giraph.writable.kryo.HadoopKryo;
25import org.apache.hadoop.io.Writable;
2627/**28 * Supplier from configuration29 * @param <T> Type of object returned30 */31publicinterface SupplierFromConf<T>
32extends Function<ImmutableClassesGiraphConfiguration, T> {
3334/**35 * Supplier from configuration, by copying given instance every time.36 *37 * @param <T> Type of object returned38 */39publicstaticclass SupplierFromConfByCopy<T> implements SupplierFromConf<T> {
40privatefinal T value;
4142publicSupplierFromConfByCopy(T value) {
43this.value = value;
44 }
4546 @Override
47public T apply(ImmutableClassesGiraphConfiguration conf) {
48return HadoopKryo.createCopy(value);
49 }
50 }
5152/**53 * Supplier from configuration returning DefaultMessageValueFactory instances.54 *55 * @param <M> Message type56 */57publicstaticclass DefaultMessageFactorySupplierFromConf<M extends Writable>
58implements SupplierFromConf<MessageValueFactory<M>> {
59privatefinal Class<M> messageClass;
6061publicDefaultMessageFactorySupplierFromConf(Class<M> messageClass) {
62this.messageClass = messageClass;
63 }
6465 @Override
66public MessageValueFactory<M> apply(
67ImmutableClassesGiraphConfiguration conf) {
68returnnew DefaultMessageValueFactory<>(messageClass, conf);
69 }
70 }
71 }