51
51
import org .openqa .selenium .remote .http .Route ;
52
52
import org .openqa .selenium .remote .tracing .Tracer ;
53
53
54
- import java .time .Duration ;
55
- import java .time .temporal .ChronoUnit ;
56
54
import java .util .Collections ;
57
55
import java .util .Set ;
58
56
import java .util .concurrent .Executors ;
57
+ import java .util .concurrent .atomic .AtomicBoolean ;
59
58
import java .util .logging .Logger ;
60
59
61
60
import static java .net .HttpURLConnection .HTTP_INTERNAL_ERROR ;
70
69
public class NodeServer extends TemplateGridServerCommand {
71
70
72
71
private static final Logger LOG = Logger .getLogger (NodeServer .class .getName ());
72
+ private final AtomicBoolean nodeRegistered = new AtomicBoolean (false );
73
73
private Node node ;
74
74
private EventBus bus ;
75
75
@@ -135,6 +135,7 @@ protected Handlers createHandlers(Config config) {
135
135
136
136
bus .addListener (NodeAddedEvent .listener (nodeId -> {
137
137
if (node .getId ().equals (nodeId )) {
138
+ nodeRegistered .set (true );
138
139
LOG .info ("Node has been added" );
139
140
}
140
141
}));
@@ -172,6 +173,7 @@ public Server<?> asServer(Config initialConfig) {
172
173
Require .nonNull ("Config" , initialConfig );
173
174
174
175
Config config = new MemoizedConfig (new CompoundConfig (initialConfig , getDefaultConfig ()));
176
+ NodeOptions nodeOptions = new NodeOptions (config );
175
177
176
178
Handlers handler = createHandlers (config );
177
179
@@ -183,11 +185,13 @@ public Server<?> asServer(Config initialConfig) {
183
185
public NettyServer start () {
184
186
super .start ();
185
187
186
- // Unlimited attempts, initial 5 seconds interval, backoff rate of 1.0005, max interval of 5 minutes
187
- RetryPolicy <Object > registrationPolicy = new RetryPolicy <>()
188
+ // Unlimited attempts, every X seconds, we assume a Node should not need more than Y minutes to register
189
+ // X defaults to 10s and Y to 120 seconds, but the user can overwrite that.
190
+ RetryPolicy <Object > registrationPolicy = new RetryPolicy <>()
188
191
.withMaxAttempts (-1 )
189
- .handleResultIf (result -> true )
190
- .withBackoff (Duration .ofSeconds (5 ).getSeconds (), Duration .ofMinutes (5 ).getSeconds (), ChronoUnit .SECONDS , 1.0005 );
192
+ .withMaxDuration (nodeOptions .getRegisterPeriod ())
193
+ .withDelay (nodeOptions .getRegisterCycle ())
194
+ .handleResultIf (result -> true );
191
195
192
196
LOG .info ("Starting registration process for node id " + node .getId ());
193
197
Executors .newSingleThreadExecutor ().submit (() -> {
@@ -201,6 +205,9 @@ public NettyServer start() {
201
205
throw new UnsupportedOperationException ("Node cannot be registered" );
202
206
}
203
207
bus .fire (new NodeStatusEvent (node .getStatus ()));
208
+ if (nodeRegistered .get ()) {
209
+ throw new InterruptedException ("Stopping registration thread." );
210
+ }
204
211
}
205
212
);
206
213
});
0 commit comments