org.infinispan.hotrod.impl.consistenthash.ConsistentHashFactory Maven / Gradle / Ivy
The newest version!
package org.infinispan.hotrod.impl.consistenthash;
import org.infinispan.hotrod.configuration.HotRodConfiguration;
import org.infinispan.commons.util.Util;
/**
* Factory for {@link org.infinispan.hotrod.impl.consistenthash.ConsistentHash} function. It will try to look
* into the configuration for consistent hash definitions as follows:
* consistent-hash.[version]=[fully qualified class implementing ConsistentHash]
* e.g.
* infinispan.client.hotrod.hash_function_impl.3=org.infinispan.hotrod.impl.consistenthash.SegmentConsistentHash
* or if using the {@link HotRodConfiguration} API,
* configuration.consistentHashImpl(3, org.infinispan.hotrod.impl.consistenthash.SegmentConsistentHash.class);
*
*
* The defaults are:
*
* - N/A (No longer used.)
* - org.infinispan.hotrod.impl.ConsistentHashV2
* - org.infinispan.hotrod.impl.SegmentConsistentHash
*
*
* @since 14.0
*/
public class ConsistentHashFactory {
private HotRodConfiguration configuration;
public void init(HotRodConfiguration configuration) {
this.configuration = configuration;
}
public T newConsistentHash(int version) {
Class extends ConsistentHash> hashFunctionClass = configuration.consistentHashImpl(version);
// TODO: Why create a brand new instance via reflection everytime a new hash topology is received? Caching???
return (T) Util.getInstance(hashFunctionClass);
}
}