Class CachedSharding<T extends Comparable<?>>

java.lang.Object
me.ahoo.cosid.sharding.CachedSharding<T>
Type Parameters:
T - the type of comparable sharding value
All Implemented Interfaces:
PreciseSharding<T>, RangeSharding<T>, Sharding<T>

@Beta public class CachedSharding<T extends Comparable<?>> extends Object implements Sharding<T>
Caching wrapper for sharding algorithms.

Caches range sharding results to reduce computation overhead for frequently accessed ranges.

  • Constructor Details

    • CachedSharding

      public CachedSharding(Sharding<T> actual)
      Creates a cached wrapper around the specified sharding algorithm.
      Parameters:
      actual - the underlying sharding algorithm
  • Method Details

    • sharding

      public @NonNull String sharding(T shardingValue)
      Description copied from interface: PreciseSharding
      Gets the node for a single sharding value.
      Specified by:
      sharding in interface PreciseSharding<T extends Comparable<?>>
      Parameters:
      shardingValue - the sharding value
      Returns:
      the node name
    • sharding

      public @NonNull Collection<String> sharding(com.google.common.collect.Range<T> shardingValue)
      Description copied from interface: RangeSharding
      Gets the nodes that should handle the given range of IDs.
      Specified by:
      sharding in interface RangeSharding<T extends Comparable<?>>
      Parameters:
      shardingValue - the range of sharding values
      Returns:
      collection of node names that should handle the range
    • getEffectiveNodes

      public @NonNull Collection<String> getEffectiveNodes()
      Description copied from interface: Sharding
      Gets all effective node names.
      Specified by:
      getEffectiveNodes in interface Sharding<T extends Comparable<?>>
      Returns:
      collection of effective node names