1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
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 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
38 | |
public class PairedPieceAndStage<S> { |
39 | |
private final AbstractPiece piece; |
40 | |
private final S executionStage; |
41 | |
|
42 | 0 | public PairedPieceAndStage(AbstractPiece piece, S executionStage) { |
43 | 0 | this.piece = piece; |
44 | 0 | this.executionStage = executionStage; |
45 | 0 | } |
46 | |
|
47 | |
public S nextExecutionStage() { |
48 | |
|
49 | 0 | return piece != null ? |
50 | 0 | (S) piece.nextExecutionStage(executionStage) : executionStage; |
51 | |
} |
52 | |
|
53 | |
public S getExecutionStage() { |
54 | 0 | return executionStage; |
55 | |
} |
56 | |
|
57 | |
public void registerReducers(BlockMasterApi masterApi) { |
58 | 0 | if (piece != null) { |
59 | 0 | piece.wrappedRegisterReducers(masterApi, executionStage); |
60 | |
} |
61 | 0 | } |
62 | |
|
63 | |
public InnerVertexSender getVertexSender(BlockWorkerSendApi sendApi) { |
64 | 0 | if (piece != null) { |
65 | 0 | return piece.getWrappedVertexSender(sendApi, executionStage); |
66 | |
} |
67 | 0 | return null; |
68 | |
} |
69 | |
|
70 | |
public void masterCompute(BlockMasterApi masterApi) { |
71 | 0 | if (piece != null) { |
72 | 0 | piece.masterCompute(masterApi, executionStage); |
73 | |
} |
74 | 0 | } |
75 | |
|
76 | |
public VertexReceiver getVertexReceiver( |
77 | |
BlockWorkerReceiveApi receiveApi) { |
78 | 0 | if (piece != null) { |
79 | 0 | return piece.getVertexReceiver(receiveApi, executionStage); |
80 | |
} |
81 | 0 | return null; |
82 | |
} |
83 | |
|
84 | |
public void workerContextSend( |
85 | |
BlockWorkerContextSendApi workerContextApi, Object workerValue) { |
86 | 0 | if (piece != null) { |
87 | 0 | piece.workerContextSend(workerContextApi, executionStage, workerValue); |
88 | |
} |
89 | 0 | } |
90 | |
|
91 | |
public void workerContextReceive( |
92 | |
BlockWorkerContextReceiveApi workerContextApi, |
93 | |
Object workerValue, List<Writable> workerMessages) { |
94 | 0 | if (piece != null) { |
95 | 0 | piece.workerContextReceive( |
96 | |
workerContextApi, executionStage, workerValue, workerMessages); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public AbstractPiece getPiece() { |
104 | 0 | return piece; |
105 | |
} |
106 | |
|
107 | |
@Override |
108 | |
public String toString() { |
109 | 0 | return "Piece " + piece + " in stage " + executionStage; |
110 | |
} |
111 | |
} |