Package me.ahoo.cosid.sharding
Class ModCycle<T extends Number & Comparable<T>>
java.lang.Object
me.ahoo.cosid.sharding.ModCycle<T>
- Type Parameters:
T- the type of number that is comparable
- All Implemented Interfaces:
PreciseSharding<T>,RangeSharding<T>,Sharding<T>
Modulo-based cyclical sharding algorithm.
Distributes IDs across nodes using modulo arithmetic.
Maps a sharding value to a node by computing: value % divisor.

-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the divisor.@NonNull Collection<String>Gets all effective node names.@NonNull Collection<String>Gets the nodes that should handle the given range of IDs.@NonNull StringGets the node for a single sharding value.
-
Constructor Details
-
ModCycle
Creates a ModCycle sharding algorithm.- Parameters:
divisor- the number of nodes to distribute acrosslogicNamePrefix- the prefix for node names
-
-
Method Details
-
getDivisor
public int getDivisor()Gets the divisor.- Returns:
- the divisor
-
sharding
Description copied from interface:PreciseShardingGets the node for a single sharding value.- Specified by:
shardingin interfacePreciseSharding<T extends Number & Comparable<T>>- Parameters:
shardingValue- the sharding value- Returns:
- the node name
-
sharding
Description copied from interface:RangeShardingGets the nodes that should handle the given range of IDs.- Specified by:
shardingin interfaceRangeSharding<T extends Number & Comparable<T>>- Parameters:
shardingValue- the range of sharding values- Returns:
- collection of node names that should handle the range
-
getEffectiveNodes
Description copied from interface:ShardingGets all effective node names.- Specified by:
getEffectiveNodesin interfaceSharding<T extends Number & Comparable<T>>- Returns:
- collection of effective node names
-