This project has retired. For details please refer to its Attic page.
PairedPieceAndStage 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.internal;
19  
20  import java.util.List;
21  
22  import org.apache.giraph.block_app.framework.api.BlockMasterApi;
23  import org.apache.giraph.block_app.framework.api.BlockWorkerContextReceiveApi;
24  import org.apache.giraph.block_app.framework.api.BlockWorkerContextSendApi;
25  import org.apache.giraph.block_app.framework.api.BlockWorkerReceiveApi;
26  import org.apache.giraph.block_app.framework.api.BlockWorkerSendApi;
27  import org.apache.giraph.block_app.framework.piece.AbstractPiece;
28  import org.apache.giraph.block_app.framework.piece.AbstractPiece.InnerVertexSender;
29  import org.apache.giraph.block_app.framework.piece.interfaces.VertexReceiver;
30  import org.apache.hadoop.io.Writable;
31  
32  /**
33   * Object holding piece with it's corresponding execution stage.
34   *
35   * @param <S> Execution stage type
36   */
37  @SuppressWarnings({ "rawtypes", "unchecked" })
38  public class PairedPieceAndStage<S> {
39    private final AbstractPiece piece;
40    private final S executionStage;
41  
42    public PairedPieceAndStage(AbstractPiece piece, S executionStage) {
43      this.piece = piece;
44      this.executionStage = executionStage;
45    }
46  
47    public S nextExecutionStage() {
48      // if piece is null, then it cannot change the execution stage
49      return piece != null ?
50        (S) piece.nextExecutionStage(executionStage) : executionStage;
51    }
52  
53    public S getExecutionStage() {
54      return executionStage;
55    }
56  
57    public void registerReducers(BlockMasterApi masterApi) {
58      if (piece != null) {
59        piece.wrappedRegisterReducers(masterApi, executionStage);
60      }
61    }
62  
63    public InnerVertexSender getVertexSender(BlockWorkerSendApi sendApi) {
64      if (piece != null) {
65        return piece.getWrappedVertexSender(sendApi, executionStage);
66      }
67      return null;
68    }
69  
70    public void masterCompute(BlockMasterApi masterApi) {
71      if (piece != null) {
72        piece.masterCompute(masterApi, executionStage);
73      }
74    }
75  
76    public VertexReceiver getVertexReceiver(
77        BlockWorkerReceiveApi receiveApi) {
78      if (piece != null) {
79        return piece.getVertexReceiver(receiveApi, executionStage);
80      }
81      return null;
82    }
83  
84    public void workerContextSend(
85        BlockWorkerContextSendApi workerContextApi, Object workerValue) {
86      if (piece != null) {
87        piece.workerContextSend(workerContextApi, executionStage, workerValue);
88      }
89    }
90  
91    public void workerContextReceive(
92        BlockWorkerContextReceiveApi workerContextApi,
93        Object workerValue, List<Writable> workerMessages) {
94      if (piece != null) {
95        piece.workerContextReceive(
96            workerContextApi, executionStage, workerValue, workerMessages);
97      }
98    }
99  
100   /**
101    * @return the piece
102    */
103   public AbstractPiece getPiece() {
104     return piece;
105   }
106 
107   @Override
108   public String toString() {
109     return "Piece " + piece + " in stage " + executionStage;
110   }
111 }