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

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

Go to download

Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces including automatic object serialization and deserialization (using typemapper and convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types such as enums and hstore.

There is a newer version: 2.0.0
Show newest version
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