![JAR search and dependency download from the Maven repository](/logo.png)
com.github.ltsopensource.core.loadbalance.ConsistentHashLoadBalance Maven / Gradle / Ivy
package com.github.ltsopensource.core.loadbalance;
import com.github.ltsopensource.core.commons.concurrent.ThreadLocalRandom;
import com.github.ltsopensource.core.support.ConsistentHashSelector;
import java.util.List;
/**
* 一致性hash算法
* Robert HG ([email protected]) on 3/25/15.
*/
public class ConsistentHashLoadBalance extends AbstractLoadBalance {
@Override
protected S doSelect(List shards, String seed) {
if(seed == null || seed.length() == 0){
seed = "HASH-".concat(String.valueOf(ThreadLocalRandom.current().nextInt()));
}
ConsistentHashSelector selector = new ConsistentHashSelector(shards);
return selector.selectForKey(seed);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy