27 lines
1.1 KiB
Java
27 lines
1.1 KiB
Java
package dev.ltms.bridged.health;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/** Fixed pane-probe limits. Pane content is never retained here. */
|
|
public final class PaneBudget {
|
|
public static final long COOLDOWN_NANOS = 60_000_000_000L;
|
|
public static final int MAX_PER_TICK = 2;
|
|
private final Map<String, Long> lastProbe = new HashMap<>();
|
|
private int cursor;
|
|
|
|
public List<String> choose(List<String> candidates, long nowNanos, long configuredCooldownNanos) {
|
|
long cooldown = Math.max(COOLDOWN_NANOS, configuredCooldownNanos);
|
|
List<String> out = new ArrayList<>();
|
|
for (int n = 0; n < candidates.size() && out.size() < MAX_PER_TICK; n++) {
|
|
String target = candidates.get((cursor + n) % candidates.size());
|
|
Long last = lastProbe.get(target);
|
|
if (last == null || nowNanos - last >= cooldown) { out.add(target); lastProbe.put(target, nowNanos); }
|
|
}
|
|
if (!candidates.isEmpty()) cursor = (cursor + 1) % candidates.size();
|
|
return List.copyOf(out);
|
|
}
|
|
}
|