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.api.giraph;
19  
20  import org.apache.giraph.block_app.framework.api.BlockWorkerContextReceiveApi;
21  import org.apache.giraph.block_app.framework.api.BlockWorkerContextSendApi;
22  import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
23  import org.apache.giraph.worker.WorkerContext;
24  import org.apache.hadoop.io.Writable;
25  import org.apache.hadoop.io.WritableComparable;
26  
27  /**
28   * Giraph implementation of BlockWorkerContextReceiveApi and
29   * BlockWorkerContextSendApi, passing all calls to WorkerContext.
30   *
31   * @param <I> vertex Id type.
32   * @param <WM> Worker message type
33   */
34  final class BlockWorkerContextApiWrapper
35      <I extends WritableComparable, WM extends Writable> implements
36      BlockWorkerContextReceiveApi<I>, BlockWorkerContextSendApi<I, WM> {
37    private final WorkerContext workerContext;
38  
39    public BlockWorkerContextApiWrapper(WorkerContext workerContext) {
40      this.workerContext = workerContext;
41    }
42  
43    @Override
44    public ImmutableClassesGiraphConfiguration<?, ?, ?> getConf() {
45      return workerContext.getConf();
46    }
47  
48    @Override
49    public int getWorkerCount() {
50      return workerContext.getWorkerCount();
51    }
52  
53    @Override
54    public int getMyWorkerIndex() {
55      return workerContext.getMyWorkerIndex();
56    }
57  
58    @Override
59    public int getWorkerForVertex(I vertexId) {
60      return workerContext.getWorkerForVertex(vertexId);
61    }
62  
63    @Override
64    public <A extends Writable> A getAggregatedValue(String name) {
65      return workerContext.getAggregatedValue(name);
66    }
67  
68    @Override
69    public <A extends Writable> void aggregate(String name, A value) {
70      workerContext.aggregate(name, value);
71    }
72  
73    @Override
74    public void sendMessageToWorker(WM message, int workerIndex) {
75      workerContext.sendMessageToWorker(message, workerIndex);
76    }
77  
78    @Override
79    public <B extends Writable> B getBroadcast(String name) {
80      return workerContext.getBroadcast(name);
81    }
82  
83    @Override
84    public long getTotalNumEdges() {
85      return workerContext.getTotalNumEdges();
86    }
87  
88    @Override
89    public long getTotalNumVertices() {
90      return workerContext.getTotalNumVertices();
91    }
92  }