This project has retired. For details please refer to its Attic page.
CreateReducersApiWrapper 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.global_comm.internal;
19  
20  import org.apache.giraph.block_app.framework.api.BlockMasterApi;
21  import org.apache.giraph.block_app.framework.api.CreateReducersApi;
22  import org.apache.giraph.block_app.framework.piece.global_comm.ReducerHandle;
23  import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
24  import org.apache.giraph.reducers.ReduceOperation;
25  import org.apache.hadoop.io.Writable;
26  
27  /**
28   * Wrapping masterApi and reducers handler into API for creating reducer
29   * handles.
30   */
31  public class CreateReducersApiWrapper implements CreateReducersApi {
32    private final BlockMasterApi masterApi;
33    private final ReducersForPieceHandler reducersApi;
34  
35    public CreateReducersApiWrapper(
36        BlockMasterApi masterApi, ReducersForPieceHandler reducersApi) {
37      this.masterApi = masterApi;
38      this.reducersApi = reducersApi;
39    }
40  
41    @Override
42    public <S, R extends Writable> ReducerHandle<S, R> createLocalReducer(
43        ReduceOperation<S, R> reduceOp) {
44      return reducersApi.createLocalReducer(
45          masterApi, reduceOp, reduceOp.createInitialValue());
46    }
47  
48    @Override
49    public <S, R extends Writable> ReducerHandle<S, R> createLocalReducer(
50        ReduceOperation<S, R> reduceOp, R globalInitialValue) {
51      return reducersApi.createLocalReducer(
52          masterApi, reduceOp, globalInitialValue);
53    }
54  
55    @Override
56    public <S, R extends Writable> ReducerHandle<S, R> createGlobalReducer(
57        ReduceOperation<S, R> reduceOp) {
58      return reducersApi.createGlobalReducer(
59          masterApi, reduceOp, reduceOp.createInitialValue());
60    }
61  
62    @Override
63    public <S, R extends Writable> ReducerHandle<S, R> createGlobalReducer(
64        ReduceOperation<S, R> reduceOp, R globalInitialValue) {
65      return reducersApi.createGlobalReducer(
66          masterApi, reduceOp, globalInitialValue);
67    }
68  
69    @Override
70    public ImmutableClassesGiraphConfiguration<?, ?, ?> getConf() {
71      return masterApi.getConf();
72    }
73  }