Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PartitionExchange |
|
| 1.25;1.25 |
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 | ||
19 | package org.apache.giraph.graph.partition; | |
20 | ||
21 | import java.util.List; | |
22 | import java.util.Map; | |
23 | import java.util.Set; | |
24 | ||
25 | import org.apache.giraph.graph.WorkerInfo; | |
26 | ||
27 | /** | |
28 | * Describes what is required to send and wait for in a potential partition | |
29 | * exchange between workers. | |
30 | */ | |
31 | public class PartitionExchange { | |
32 | /** Workers that I am dependent on before I can continue */ | |
33 | private final Set<WorkerInfo> myDependencyWorkerSet; | |
34 | /** Workers that I need to sent partitions to */ | |
35 | private final Map<WorkerInfo, List<Integer>> sendWorkerPartitionMap; | |
36 | ||
37 | /** | |
38 | * Only constructor. | |
39 | * | |
40 | * @param myDependencyWorkerSet All the workers I must wait for | |
41 | * @param sendWorkerPartitionMap Partitions I need to send to other workers | |
42 | */ | |
43 | public PartitionExchange( | |
44 | Set<WorkerInfo> myDependencyWorkerSet, | |
45 | 218 | Map<WorkerInfo, List<Integer>> sendWorkerPartitionMap) { |
46 | 218 | this.myDependencyWorkerSet = myDependencyWorkerSet; |
47 | 218 | this.sendWorkerPartitionMap = sendWorkerPartitionMap; |
48 | 218 | } |
49 | ||
50 | /** | |
51 | * Get the workers that I must wait for | |
52 | * | |
53 | * @return Set of workers I must wait for | |
54 | */ | |
55 | public Set<WorkerInfo> getMyDependencyWorkerSet() { | |
56 | 194 | return myDependencyWorkerSet; |
57 | } | |
58 | ||
59 | /** | |
60 | * Get a mapping of worker to list of partition ids I need to send to. | |
61 | * | |
62 | * @return Mapping of worker to partition id list I will send to. | |
63 | */ | |
64 | public Map<WorkerInfo, List<Integer>> getSendWorkerPartitionMap() { | |
65 | 194 | return sendWorkerPartitionMap; |
66 | } | |
67 | ||
68 | /** | |
69 | * Is this worker involved in a partition exchange? Receiving or sending? | |
70 | * | |
71 | * @return True if needs to be involved in the exchange, false otherwise. | |
72 | */ | |
73 | public boolean doExchange() { | |
74 | 0 | return !myDependencyWorkerSet.isEmpty() || |
75 | !sendWorkerPartitionMap.isEmpty(); | |
76 | } | |
77 | } |