[grid] Leverage Grid Model to check capacity before polling the queue
@@ -148,10 +148,9 @@ public void run() {
writeLock.lock();
try {
if (!requestIds.isEmpty()) {
- boolean hasCapacity = nodes
- .keySet()
- .stream()
- .anyMatch(key -> nodes.get(key).getStatus().hasCapacity());
+ Set<NodeStatus> availableNodes = ImmutableSet.copyOf(getAvailableNodes());
+ boolean hasCapacity = availableNodes.stream()
+ .anyMatch(NodeStatus::hasCapacity);
if (hasCapacity) {
RequestId reqId = requestIds.poll();
if (reqId != null) {
