@Immutable public final class UniformAcrossAllShards extends DeliveryStrategy implements java.io.Serializable
Uses a hash code of the entity identifier and the remainder of its division by the total number of shards to determine the index of a shard, at which the modification is allowed. To reach the consistency of the hash code values across JVMs, the MurmurHash3, x86 variant is used.
While Guava's Hashing
is marked @Beta
, it is still the best option
for hashing functions — not to involve any heavy-weight third-party hashing
solutions.
Modifier and Type | Method and Description |
---|---|
static DeliveryStrategy |
forNumber(int totalShards)
Creates a strategy of uniform target distribution across shards, for a given shard number.
|
io.spine.server.delivery.ShardIndex |
indexFor(java.lang.Object entityId,
io.spine.type.TypeUrl entityStateType)
Determines the shard index for the messages heading to the entity with the specified target
identifier.
|
int |
shardCount()
Tells how many shards there are according to this strategy.
|
static DeliveryStrategy |
singleShard()
Returns a pre-defined strategy instance, which defines a single shard and puts all
the targets into it.
|
determineIndex
public static DeliveryStrategy forNumber(int totalShards)
totalShards
- a number of shardspublic io.spine.server.delivery.ShardIndex indexFor(java.lang.Object entityId, io.spine.type.TypeUrl entityStateType)
DeliveryStrategy
indexFor
in class DeliveryStrategy
entityId
- the identifier of the entity, to which the messages are dispatchedentityStateType
- the type URL of the entity, to which the messages are dispatchedpublic int shardCount()
DeliveryStrategy
shardCount
in class DeliveryStrategy
public static DeliveryStrategy singleShard()