All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.astyanax.recipes.queue.shard.KeyModShardPolicy Maven / Gradle / Ivy

There is a newer version: 3.10.2
Show newest version
package com.netflix.astyanax.recipes.queue.shard;

import com.netflix.astyanax.recipes.queue.Message;
import com.netflix.astyanax.recipes.queue.MessageQueueMetadata;

/**
 * Sharding based on the key with fallback to time mod sharding
 * @author elandau
 *
 */
public class KeyModShardPolicy extends TimeModShardPolicy {
    private static KeyModShardPolicy instance = new KeyModShardPolicy();

    public static KeyModShardPolicy getInstance() {
        return instance;
    }
    
    @Override
    public int getMessageShard(Message message, MessageQueueMetadata settings) {
        if (message.hasKey())
            return message.getKey().hashCode() % settings.getShardCount();
        else
            return super.getMessageShard(message, settings);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy