Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GraphState |
|
| 1.0;1 |
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.graph; | |
19 | ||
20 | import org.apache.giraph.comm.WorkerClientServer; | |
21 | import org.apache.hadoop.io.Writable; | |
22 | import org.apache.hadoop.io.WritableComparable; | |
23 | import org.apache.hadoop.mapreduce.Mapper; | |
24 | ||
25 | /** | |
26 | * Global state of the graph. Should be treated as a singleton (but is kept | |
27 | * as a regular bean to facilitate ease of unit testing) | |
28 | * | |
29 | * @param <I> Vertex id | |
30 | * @param <V> Vertex data | |
31 | * @param <E> Edge data | |
32 | * @param <M> Message data | |
33 | */ | |
34 | @SuppressWarnings("rawtypes") | |
35 | 25 | public class GraphState<I extends WritableComparable, V extends Writable, |
36 | E extends Writable, M extends Writable> { | |
37 | /** Graph-wide superstep */ | |
38 | 25 | private long superstep = 0; |
39 | /** Graph-wide number of vertices */ | |
40 | 25 | private long numVertices = -1; |
41 | /** Graph-wide number of edges */ | |
42 | 25 | private long numEdges = -1; |
43 | /** Graph-wide map context */ | |
44 | private Mapper.Context context; | |
45 | /** Graph-wide BSP Mapper for this Vertex */ | |
46 | private GraphMapper<I, V, E, M> graphMapper; | |
47 | /** Graph-wide worker communications */ | |
48 | private WorkerClientServer<I, V, E, M> workerCommunications; | |
49 | ||
50 | public long getSuperstep() { | |
51 | 5418 | return superstep; |
52 | } | |
53 | ||
54 | /** | |
55 | * Set the current superstep. | |
56 | * | |
57 | * @param superstep Current superstep to use. | |
58 | * @return Returns this object. | |
59 | */ | |
60 | public GraphState<I, V, E, M> setSuperstep(long superstep) { | |
61 | 435 | this.superstep = superstep; |
62 | 435 | return this; |
63 | } | |
64 | ||
65 | public long getTotalNumVertices() { | |
66 | 1563 | return numVertices; |
67 | } | |
68 | ||
69 | /** | |
70 | * Set the current number of vertices. | |
71 | * | |
72 | * @param numVertices Current number of vertices. | |
73 | * @return Returns this object. | |
74 | */ | |
75 | public GraphState<I, V, E, M> setTotalNumVertices(long numVertices) { | |
76 | 436 | this.numVertices = numVertices; |
77 | 436 | return this; |
78 | } | |
79 | ||
80 | public long getTotalNumEdges() { | |
81 | 50 | return numEdges; |
82 | } | |
83 | ||
84 | /** | |
85 | * Set the current number of edges. | |
86 | * | |
87 | * @param numEdges Current number of edges. | |
88 | * @return Returns this object. | |
89 | */ | |
90 | public GraphState<I, V, E, M> setTotalNumEdges(long numEdges) { | |
91 | 436 | this.numEdges = numEdges; |
92 | 436 | return this; |
93 | } | |
94 | ||
95 | public Mapper.Context getContext() { | |
96 | 43 | return context; |
97 | } | |
98 | ||
99 | /** | |
100 | * Set the current context. | |
101 | * | |
102 | * @param context Current context. | |
103 | * @return Returns this object. | |
104 | */ | |
105 | public GraphState<I, V, E, M> setContext(Mapper.Context context) { | |
106 | 265 | this.context = context; |
107 | 265 | return this; |
108 | } | |
109 | ||
110 | public GraphMapper<I, V, E, M> getGraphMapper() { | |
111 | 3066 | return graphMapper; |
112 | } | |
113 | ||
114 | /** | |
115 | * Set the current graph mapper. | |
116 | * | |
117 | * @param graphMapper Current graph mapper. | |
118 | * @return Returns this object. | |
119 | */ | |
120 | public GraphState<I, V, E, M> setGraphMapper( | |
121 | GraphMapper<I, V, E, M> graphMapper) { | |
122 | 241 | this.graphMapper = graphMapper; |
123 | 241 | return this; |
124 | } | |
125 | ||
126 | /** | |
127 | * Set the current worker communications. | |
128 | * | |
129 | * @param workerCommunications Current worker communications. | |
130 | * @return Returns this object. | |
131 | */ | |
132 | public GraphState<I, V, E, M> setWorkerCommunications( | |
133 | WorkerClientServer<I, V, E, M> workerCommunications) { | |
134 | 24 | this.workerCommunications = workerCommunications; |
135 | 24 | return this; |
136 | } | |
137 | ||
138 | public WorkerClientServer<I, V, E, M> getWorkerCommunications() { | |
139 | 2913 | return workerCommunications; |
140 | } | |
141 | } |