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.master;
1920import java.io.DataInput;
21import java.io.DataOutput;
22import java.io.IOException;
2324import org.apache.giraph.aggregators.Aggregator;
25import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable;
26import org.apache.giraph.utils.ReflectionUtils;
27import org.apache.giraph.utils.WritableUtils;
28import org.apache.hadoop.io.Writable;
2930/**31 * Writable representation of aggregated value32 *33 * @param <A> Aggregation object type34 */35publicclass AggregatorBroadcast<A extends Writable>
36extendsDefaultImmutableClassesGiraphConfigurable37implements Writable {
38/**Aggregator class */39private Class<? extends Aggregator<A>> aggregatorClass;
40/** Aggregated value */41private A value;
4243/** Constructor */44publicAggregatorBroadcast() {
45 }
4647/**48 * Constructor49 * @param aggregatorClass Aggregator class50 * @param value Aggregated value51 */52publicAggregatorBroadcast(
53 Class<? extends Aggregator<A>> aggregatorClass, A value) {
54this.aggregatorClass = aggregatorClass;
55this.value = value;
56 }
5758public A getValue() {
59return value;
60 }
6162 @Override
63publicvoid write(DataOutput out) throws IOException {
64 WritableUtils.writeClass(aggregatorClass, out);
65 value.write(out);
66 }
6768 @Override
69publicvoid readFields(DataInput in) throws IOException {
70 aggregatorClass = WritableUtils.readClass(in);
71 value = ReflectionUtils.newInstance(aggregatorClass, getConf())
72 .createInitialValue();
73 value.readFields(in);
74 }
75 }