21
21
import org .openqa .selenium .internal .Require ;
22
22
import org .openqa .selenium .json .JsonInput ;
23
23
import org .openqa .selenium .json .TypeToken ;
24
+ import org .redisson .api .annotation .REntity ;
25
+ import org .redisson .api .annotation .RId ;
26
+ import org .redisson .api .annotation .RIndex ;
24
27
28
+ import java .io .Serializable ;
25
29
import java .net .URI ;
26
30
import java .time .Duration ;
27
31
import java .time .Instant ;
34
38
import static java .util .Collections .unmodifiableMap ;
35
39
import static java .util .Collections .unmodifiableSet ;
36
40
41
+ @ REntity
37
42
public class NodeStatus {
38
43
39
- private final NodeId nodeId ;
40
- private final URI externalUri ;
41
- private final int maxSessionCount ;
42
- private final Set <Slot > slots ;
43
- private final Availability availability ;
44
+ @ RId
45
+ private NodeId nodeId ;
46
+
47
+ private URI externalUri ;
48
+ private int maxSessionCount ;
49
+ private Set <Slot > slots ;
50
+ private Availability availability ;
44
51
private Duration heartbeatPeriod ;
45
- private final String version ;
46
- private final Map <String , String > osInfo ;
52
+ private String version ;
53
+ private Map <String , String > osInfo ;
47
54
private long touched = System .currentTimeMillis ();
48
55
56
+ public NodeStatus () {
57
+ }
58
+
49
59
public NodeStatus (
50
60
NodeId nodeId ,
51
61
URI externalUri ,
@@ -69,7 +79,7 @@ public NodeStatus(
69
79
70
80
public static NodeStatus fromJson (JsonInput input ) {
71
81
NodeId nodeId = null ;
72
- URI uri = null ;
82
+ URI externalUri = null ;
73
83
int maxSessions = 0 ;
74
84
Set <Slot > slots = null ;
75
85
Availability availability = null ;
@@ -88,7 +98,7 @@ public static NodeStatus fromJson(JsonInput input) {
88
98
heartbeatPeriod = Duration .ofMillis (input .read (Long .class ));
89
99
break ;
90
100
91
- case "id " :
101
+ case "nodeId " :
92
102
nodeId = input .read (NodeId .class );
93
103
break ;
94
104
@@ -101,8 +111,8 @@ public static NodeStatus fromJson(JsonInput input) {
101
111
}.getType ());
102
112
break ;
103
113
104
- case "uri " :
105
- uri = input .read (URI .class );
114
+ case "externalUri " :
115
+ externalUri = input .read (URI .class );
106
116
break ;
107
117
108
118
case "version" :
@@ -122,7 +132,7 @@ public static NodeStatus fromJson(JsonInput input) {
122
132
123
133
return new NodeStatus (
124
134
nodeId ,
125
- uri ,
135
+ externalUri ,
126
136
maxSessions ,
127
137
slots ,
128
138
availability ,
@@ -136,56 +146,100 @@ public boolean hasCapability(Capabilities caps) {
136
146
}
137
147
138
148
public boolean hasCapacity () {
139
- return slots .stream ().anyMatch (slot -> ! slot .getSession (). isPresent () );
149
+ return slots .stream ().anyMatch (slot -> slot .getSession () == null );
140
150
}
141
151
142
152
public boolean hasCapacity (Capabilities caps ) {
143
153
return slots .stream ()
144
- .anyMatch (slot -> !slot .getSession ().isPresent () && slot .isSupporting (caps ));
154
+ .anyMatch (slot -> slot .getSession () == null && slot .isSupporting (caps ));
155
+ }
156
+
157
+ public int getMaxSessionCount () {
158
+ return maxSessionCount ;
159
+ }
160
+
161
+ public void setMaxSessionCount (int maxSessionCount ) {
162
+ this .maxSessionCount = maxSessionCount ;
145
163
}
146
164
147
- public NodeId getId () {
165
+ public NodeId getNodeId () {
148
166
return nodeId ;
149
167
}
150
168
151
- public URI getUri () {
169
+ public void setNodeId (NodeId nodeId ) {
170
+ this .nodeId = nodeId ;
171
+ }
172
+
173
+ public URI getExternalUri () {
152
174
return externalUri ;
153
175
}
154
176
155
- public int getMaxSessionCount ( ) {
156
- return maxSessionCount ;
177
+ public void setExternalUri ( URI externalUri ) {
178
+ this . externalUri = externalUri ;
157
179
}
158
180
159
181
public Set <Slot > getSlots () {
160
182
return slots ;
161
183
}
162
184
185
+ public void setSlots (Set <Slot > slots ) {
186
+ this .slots = slots ;
187
+ }
188
+
163
189
public Availability getAvailability () {
164
190
return availability ;
165
191
}
166
192
193
+ public void setAvailability (Availability availability ) {
194
+ this .availability = availability ;
195
+ }
196
+
197
+ public Duration getHeartbeatPeriod () {
198
+ return heartbeatPeriod ;
199
+ }
200
+
201
+ public void setHeartbeatPeriod (Duration heartbeatPeriod ) {
202
+ this .heartbeatPeriod = heartbeatPeriod ;
203
+ }
204
+
167
205
public String getVersion () {
168
206
return version ;
169
207
}
170
208
209
+ public void setVersion (String version ) {
210
+ this .version = version ;
211
+ }
212
+
171
213
public Map <String , String > getOsInfo () {
172
214
return osInfo ;
173
215
}
174
216
217
+ public void setOsInfo (Map <String , String > osInfo ) {
218
+ this .osInfo = osInfo ;
219
+ }
220
+
221
+ public long getTouched () {
222
+ return touched ;
223
+ }
224
+
225
+ public void setTouched (long touched ) {
226
+ this .touched = touched ;
227
+ }
228
+
175
229
public float getLoad () {
176
230
float inUse = slots .parallelStream ()
177
- .filter (slot -> slot .getSession (). isPresent () )
231
+ .filter (slot -> slot .getSession () != null )
178
232
.count ();
179
233
180
234
return (inUse / (float ) maxSessionCount ) * 100f ;
181
235
}
182
236
183
237
public long getLastSessionCreated () {
184
- return slots .parallelStream ()
185
- .map (Slot ::getLastStarted )
186
- .mapToLong (Instant ::toEpochMilli )
187
- .max ()
188
- .orElse (0 );
238
+ return slots .parallelStream ()
239
+ .map (Slot ::getLastStarted )
240
+ .mapToLong (Instant ::toEpochMilli )
241
+ .max ()
242
+ .orElse (0 );
189
243
}
190
244
191
245
public Duration heartbeatPeriod () {
@@ -208,11 +262,11 @@ public boolean equals(Object o) {
208
262
209
263
NodeStatus that = (NodeStatus ) o ;
210
264
return Objects .equals (this .nodeId , that .nodeId ) &&
211
- Objects .equals (this .externalUri , that .externalUri ) &&
212
- this .maxSessionCount == that .maxSessionCount &&
213
- Objects .equals (this .slots , that .slots ) &&
214
- Objects .equals (this .availability , that .availability ) &&
215
- Objects .equals (this .version , that .version );
265
+ Objects .equals (this .externalUri , that .externalUri ) &&
266
+ this .maxSessionCount == that .maxSessionCount &&
267
+ Objects .equals (this .slots , that .slots ) &&
268
+ Objects .equals (this .availability , that .availability ) &&
269
+ Objects .equals (this .version , that .version );
216
270
}
217
271
218
272
@ Override
@@ -222,8 +276,8 @@ public int hashCode() {
222
276
223
277
private Map <String , Object > toJson () {
224
278
Map <String , Object > toReturn = new TreeMap <>();
225
- toReturn .put ("id " , nodeId );
226
- toReturn .put ("uri " , externalUri );
279
+ toReturn .put ("nodeId " , nodeId );
280
+ toReturn .put ("externalUri " , externalUri );
227
281
toReturn .put ("maxSessions" , maxSessionCount );
228
282
toReturn .put ("slots" , slots );
229
283
toReturn .put ("availability" , availability );
0 commit comments