feat(sj_1.2.0-beta1):增加第一和最后一个路由功能

This commit is contained in:
srzou 2024-07-30 16:28:33 +08:00
parent 04f8137b3f
commit 838fe806fc
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,17 @@
package com.aizuda.snailjob.server.common.allocate.client;
import com.aizuda.snailjob.server.common.ClientLoadBalance;
import java.util.TreeSet;
public class ClientLoadBalanceFirst implements ClientLoadBalance {
@Override
public String route(String key, TreeSet<String> clientAllAddressSet) {
return clientAllAddressSet.first();
}
@Override
public int routeType() {
return ClientLoadBalanceManager.AllocationAlgorithmEnum.FIRST.getType();
}
}

View File

@ -0,0 +1,17 @@
package com.aizuda.snailjob.server.common.allocate.client;
import com.aizuda.snailjob.server.common.ClientLoadBalance;
import java.util.TreeSet;
public class ClientLoadBalanceLast implements ClientLoadBalance {
@Override
public String route(String key, TreeSet<String> clientAllAddressSet) {
return clientAllAddressSet.last();
}
@Override
public int routeType() {
return ClientLoadBalanceManager.AllocationAlgorithmEnum.LAST.getType();
}
}

View File

@ -29,7 +29,9 @@ public class ClientLoadBalanceManager {
CONSISTENT_HASH(1, new ClientLoadBalanceConsistentHash(100)),
RANDOM(2, new ClientLoadBalanceRandom()),
LRU(3, new ClientLoadBalanceLRU(100)),
ROUND(4, new ClientLoadBalanceRound());
ROUND(4, new ClientLoadBalanceRound()),
FIRST(5, new ClientLoadBalanceFirst()),
LAST(6, new ClientLoadBalanceLast());
private final int type;
private final ClientLoadBalance clientLoadBalance;