gianm commented on code in PR #16064:
URL: https://github.com/apache/druid/pull/16064#discussion_r1515003440
##########
server/src/main/java/org/apache/druid/discovery/BaseNodeRoleWatcher.java:
##########
@@ -352,6 +345,24 @@ public void resetNodes(Map<String, DiscoveryDruidNode>
fullNodes)
}
}
+ static void scheduleTimeout(
Review Comment:
This works, but it'd be nicer as a non-static method, so the caller doesn't
need to pass in the executor. The watcher has the `listenerExecutor` already,
so as a non-static this would be:
```java
void scheduleTimeout(long timeoutSeconds)
{
listenerExecutor.schedule(
this::cacheInitializedTimedOut,
timeout,
TimeUnit.SECONDS
);
}
```
##########
server/src/test/java/org/apache/druid/discovery/BaseNodeRoleWatcherTest.java:
##########
@@ -161,16 +160,18 @@ public void testRegisterListenerBeforeTimeout() throws
InterruptedException
assertListener(listener1, false, Collections.emptyList(),
Collections.emptyList());
- Assert.assertTrue(listener1.ready.await(1500, TimeUnit.MILLISECONDS));
+ BaseNodeRoleWatcher.scheduleTimeout(nodeRoleWatcher, exec, 0);
Review Comment:
Looks much nicer, thank you!
##########
server/src/main/java/org/apache/druid/discovery/BaseNodeRoleWatcher.java:
##########
@@ -76,28 +76,24 @@ public BaseNodeRoleWatcher(
NodeRole nodeRole
)
{
- this(listenerExecutor, nodeRole, DEFAULT_TIMEOUT_SECONDS);
+ this.nodeRole = nodeRole;
+ this.listenerExecutor = listenerExecutor;
}
- BaseNodeRoleWatcher(
+ public static BaseNodeRoleWatcher create(
ScheduledExecutorService listenerExecutor,
- NodeRole nodeRole,
- long timeout
+ NodeRole nodeRole
)
{
- this.nodeRole = nodeRole;
- this.listenerExecutor = listenerExecutor;
- this.listenerExecutor.schedule(
- this::cacheInitializedTimedOut,
- timeout,
- TimeUnit.SECONDS
- );
+ BaseNodeRoleWatcher nodeRoleWatcher = new
BaseNodeRoleWatcher(listenerExecutor, nodeRole);
+ scheduleTimeout(nodeRoleWatcher, listenerExecutor,
DEFAULT_TIMEOUT_SECONDS);
Review Comment:
See other comment about making `scheduleTimeout` an instance method; then
this would simply be `nodeRoleWatcher.scheduleTimeout(DEFAULT_TIMEOUT_SECONDS);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]