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

de.zalando.sprocwrapper.sharding.VirtualShardAwareIdStrategy Maven / Gradle / Ivy

package de.zalando.sprocwrapper.sharding;

/**
 * extract the encoded shard bits from a long shard-aware ID.
 *
 * @author  jmussler
 * @author  hjacobs
 */
public class VirtualShardAwareIdStrategy extends VirtualShardKeyStrategy {

    @Override
    public int getShardId(final Object[] objs) {
        if (objs == null || objs.length == 0) {
            return 0;
        }

        if (objs[0] == null) {
            return 0;
        }

        long id = (objs[0] instanceof Long ? (Long) objs[0] : (Integer) objs[0]);

        // 10 lower bits represent sequence number
        // extract the next 9 bit as virtual shard id
        return (int) (id >> 10) & 0x1ff;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy