42 lines
1.1 KiB
Java
42 lines
1.1 KiB
Java
package dev.ltms.bridged.placement;
|
|
|
|
/**
|
|
* Factory for the built-in placement policies.
|
|
*/
|
|
public final class PlacementPolicies {
|
|
|
|
private PlacementPolicies() {
|
|
}
|
|
|
|
/**
|
|
* Resolve a policy name from config. Absent/blank values and {@code "fixed"} return the
|
|
* backward-compatible fixed policy; unknown names throw.
|
|
*/
|
|
public static PlacementPolicy fromName(String name) {
|
|
String n = (name == null) ? "" : name.toLowerCase();
|
|
if (n.isBlank() || "fixed".equals(n)) {
|
|
return fixed();
|
|
}
|
|
if ("weighted".equals(n)) {
|
|
return weighted();
|
|
}
|
|
if ("round-robin".equals(n)) {
|
|
return roundRobin();
|
|
}
|
|
throw new IllegalArgumentException("unknown placement policy '" + name
|
|
+ "' — must be one of: fixed, round-robin, weighted");
|
|
}
|
|
|
|
public static PlacementPolicy fixed() {
|
|
return new FixedPlacementPolicy();
|
|
}
|
|
|
|
public static PlacementPolicy weighted() {
|
|
return new WeightedRoundRobinPolicy();
|
|
}
|
|
|
|
public static PlacementPolicy roundRobin() {
|
|
return new RoundRobinPlacementPolicy();
|
|
}
|
|
}
|