CosIdShardingDecorator

class CosIdShardingDecorator(sharding: PreciseSharding<Long>, hashFunction: (String) -> Long = DEFAULT_HASH_FUNCTION) : AggregateIdSharding

Decorator that adapts a numeric sharding strategy for aggregate IDs using a hash function.

This class wraps a PreciseSharding implementation and converts aggregate IDs to Long values using a hash function before delegating to the underlying sharding strategy. This allows using existing numeric sharding algorithms with string-based aggregate IDs.

The default hash function extracts the sequence number from globally unique IDs, providing good distribution characteristics.

Example usage:

val numericSharding = ModuloSharding(4) // Shards into 4 buckets
val aggregateSharding = CosIdShardingDecorator(numericSharding)

val shard = aggregateSharding.sharding(aggregateId) // Returns "0", "1", "2", or "3"

See also

PreciseSharding

Constructors

Link copied to clipboard
constructor(sharding: PreciseSharding<Long>, hashFunction: (String) -> Long = DEFAULT_HASH_FUNCTION)

Functions

Link copied to clipboard
open override fun sharding(aggregateId: AggregateId): String

Determines the shard by hashing the aggregate ID and delegating to the numeric sharding strategy.