24 lines
815 B
Java
24 lines
815 B
Java
package dev.ltms.bridged.placement;
|
|
|
|
import java.util.List;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
/**
|
|
* Deterministic round-robin over the profiles that still have capacity and are not known to be
|
|
* unreachable. The index advances only on successful selections so the distribution stays even
|
|
* across spawns.
|
|
*/
|
|
final class RoundRobinPlacementPolicy implements PlacementPolicy {
|
|
|
|
private final AtomicInteger index = new AtomicInteger(0);
|
|
|
|
@Override
|
|
public synchronized PlacementCandidate select(PlacementContext ctx) {
|
|
List<PlacementCandidate> available = PlacementPolicyUtil.available(ctx);
|
|
if (available.isEmpty()) {
|
|
throw PlacementPolicyUtil.emptyException(ctx);
|
|
}
|
|
return available.get(index.getAndIncrement() % available.size());
|
|
}
|
|
}
|