Java Code Examples for net.spy.memcached.DefaultHashAlgorithm#KETAMA_HASH

The following examples show how to use net.spy.memcached.DefaultHashAlgorithm#KETAMA_HASH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EVCacheNodeLocator.java    From EVCache with Apache License 2.0 5 votes vote down vote up
/**
 * Setup the KetamaNodeLocator with the list of nodes it should use.
 *
 * @param nodes
 *            a List of MemcachedNodes for this KetamaNodeLocator to use in
 *            its continuum
 */
protected final void setKetamaNodes(List<MemcachedNode> nodes) {
    TreeMap<Long, MemcachedNode> newNodeMap = new TreeMap<Long, MemcachedNode>();
    final int numReps = config.getNodeRepetitions();
    for (MemcachedNode node : nodes) {
        // Ketama does some special work with md5 where it reuses chunks.
        if (hashingAlgorithm == DefaultHashAlgorithm.KETAMA_HASH) {
            for (int i = 0; i < numReps / 4; i++) {
                final String hashString = config.getKeyForNode(node, i);
                byte[] digest = DefaultHashAlgorithm.computeMd5(hashString);
                if (log.isDebugEnabled()) log.debug("digest : " + digest);
                for (int h = 0; h < 4; h++) {
                    long k = ((long) (digest[3 + h * 4] & 0xFF) << 24)
                            | ((long) (digest[2 + h * 4] & 0xFF) << 16)
                            | ((long) (digest[1 + h * 4] & 0xFF) << 8)
                            | (digest[h * 4] & 0xFF);
                    newNodeMap.put(Long.valueOf(k), node);
                    if (log.isDebugEnabled()) log.debug("Key : " + hashString + " ; hash : " + k + "; node " + node );
                }
            }
        } else {
            for (int i = 0; i < numReps; i++) {
                final Long hashL = Long.valueOf(hashingAlgorithm.hash(config.getKeyForNode(node, i)));
                newNodeMap.put(hashL, node);
            }
        }
    }
    if (log.isDebugEnabled()) log.debug("NewNodeMapSize : " + newNodeMap.size() + "; MapSize : " + (numReps * nodes.size()));
    if (log.isTraceEnabled()) {
        for(Long key : newNodeMap.keySet()) {
            log.trace("Hash : " + key + "; Node : " + newNodeMap.get(key));
        }
    }
    ketamaNodes = newNodeMap;
}
 
Example 2
Source File: BaseConnectionFactory.java    From EVCache with Apache License 2.0 5 votes vote down vote up
BaseConnectionFactory(EVCacheClient client, int len, Property<Integer> _operationTimeout, long opMaxBlockTime) {
    super(len, BinaryConnectionFactory.DEFAULT_READ_BUFFER_SIZE, DefaultHashAlgorithm.KETAMA_HASH);
    this.opMaxBlockTime = opMaxBlockTime;
    this.operationTimeout = _operationTimeout;
    this.client = client;
    this.startTime = System.currentTimeMillis();

    this.appName = client.getAppName();
    this.failureMode = client.getPool().getEVCacheClientPoolManager().getEVCacheConfig().getPropertyRepository().get(this.client.getServerGroupName() + ".failure.mode", String.class).orElseGet(appName + ".failure.mode").orElse("Retry");
    this.name = appName + "-" + client.getServerGroupName() + "-" + client.getId();
}
 
Example 3
Source File: BaseAsciiConnectionFactory.java    From EVCache with Apache License 2.0 5 votes vote down vote up
BaseAsciiConnectionFactory(EVCacheClient client, int len, Property<Integer> _operationTimeout, long opMaxBlockTime) {
    super(len, DefaultConnectionFactory.DEFAULT_READ_BUFFER_SIZE, DefaultHashAlgorithm.KETAMA_HASH);
    this.opMaxBlockTime = opMaxBlockTime;
    this.operationTimeout = _operationTimeout;
    this.client = client;
    this.startTime = System.currentTimeMillis();

    this.appName = client.getAppName();
    this.failureMode = client.getPool().getEVCacheClientPoolManager().getEVCacheConfig().getPropertyRepository().get(this.client.getServerGroupName() + ".failure.mode", String.class).orElseGet(appName + ".failure.mode").orElse("Retry");
    this.name = appName + "-" + client.getServerGroupName() + "-" + client.getId();
}
 
Example 4
Source File: BaseConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public NodeLocator createLocator(List<MemcachedNode> list) {
    this.locator = new EVCacheNodeLocator(client, list,
            DefaultHashAlgorithm.KETAMA_HASH, new EVCacheKetamaNodeLocatorConfiguration(client));
    return locator;
}
 
Example 5
Source File: BaseAsciiConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public NodeLocator createLocator(List<MemcachedNode> list) {
    this.locator = new EVCacheNodeLocator(client, list, DefaultHashAlgorithm.KETAMA_HASH, new EVCacheKetamaNodeLocatorConfiguration(client));
    return locator;
}
 
Example 6
Source File: DIConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
@Override
public NodeLocator createLocator(List<MemcachedNode> list) {
    this.locator = new EVCacheNodeLocator(client, list,  DefaultHashAlgorithm.KETAMA_HASH, new DIEVCacheKetamaNodeLocatorConfiguration(client, eurekaClient));
    return locator;
}
 
Example 7
Source File: DIAsciiConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
@Override
public NodeLocator createLocator(List<MemcachedNode> list) {
    this.locator = new EVCacheNodeLocator(client, list,  DefaultHashAlgorithm.KETAMA_HASH, new DIEVCacheKetamaNodeLocatorConfiguration(client, eurekaClient));
    return locator;
}