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.factories;
1920import com.google.common.base.MoreObjects;
21import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22import org.apache.giraph.utils.WritableUtils;
23import org.apache.hadoop.io.Writable;
2425/**26 * Factory class to create default message values.27 *28 * @param <M> Message Value29 */30publicclass DefaultMessageValueFactory<M extends Writable>
31implements MessageValueFactory<M> {
32/** Message value class */33privatefinal Class<M> messageValueClass;
34/** Configuration */35privatefinalImmutableClassesGiraphConfiguration conf;
3637/**38 * Constructor39 * @param messageValueClass message value class40 * @param conf configuration41 */42publicDefaultMessageValueFactory(Class<M> messageValueClass,
43ImmutableClassesGiraphConfiguration conf) {
44this.messageValueClass = messageValueClass;
45this.conf = conf;
46 }
4748 @Override public M newInstance() {
49return WritableUtils.createWritable(messageValueClass, conf);
50 }
5152 @Override public String toString() {
53return MoreObjects.toStringHelper(this)
54 .add("messageValueClass", messageValueClass)
55 .toString();
56 }
57 }