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.global_comm;
1920import org.apache.giraph.block_app.framework.api.BlockMasterApi;
21import org.apache.giraph.master.MasterGlobalCommUsage;
22import org.apache.giraph.worker.WorkerBroadcastUsage;
2324/**25 * Handle that wraps both reducerHandle and broadcastHandle, so callers26 * don't need to have two fields.27 *28 * @param <S> Single value type29 * @param <R> Reduced value type30 */31publicclass ReducerAndBroadcastWrapperHandle<S, R> {
32private ReducerHandle<S, R> reducerHandle;
33private BroadcastHandle<R> broadcastHandle;
3435/** Set reducer handle to just registered handle */36publicvoid registeredReducer(ReducerHandle<S, R> reducerHandle) {
37this.reducerHandle = reducerHandle;
38 }
3940/** Reduce single value */41publicvoid reduce(S valueToReduce) {
42 reducerHandle.reduce(valueToReduce);
43 }
4445/** Get reduced value */46public R getReducedValue(MasterGlobalCommUsage master) {
47return reducerHandle.getReducedValue(master);
48 }
4950/**51 * Broadcast reduced value from master52 */53publicvoid broadcastValue(BlockMasterApi master) {
54 broadcastHandle = reducerHandle.broadcastValue(master);
55 }
5657/** Get broadcasted value */58public R getBroadcast(WorkerBroadcastUsage worker) {
59return broadcastHandle.getBroadcast(worker);
60 }
61 }