Class DefaultGroupedIdSegmentDistributor

java.lang.Object
me.ahoo.cosid.segment.grouped.DefaultGroupedIdSegmentDistributor
All Implemented Interfaces:
Grouped, GroupedIdSegmentDistributor, IdSegmentDistributor

public class DefaultGroupedIdSegmentDistributor extends Object implements GroupedIdSegmentDistributor
  • Constructor Details

  • Method Details

    • groupBySupplier

      public GroupBySupplier groupBySupplier()
    • getNamespace

      @Nonnull public String getNamespace()
      Description copied from interface: IdSegmentDistributor
      Get the namespace for this distributor.

      The namespace provides a logical grouping for ID segments, allowing multiple independent segment spaces within the same system.

      Specified by:
      getNamespace in interface IdSegmentDistributor
      Returns:
      The namespace
    • getName

      @Nonnull public String getName()
      Description copied from interface: IdSegmentDistributor
      Get the name for this distributor.

      The name uniquely identifies this distributor within its namespace.

      Specified by:
      getName in interface IdSegmentDistributor
      Returns:
      The name
    • getStep

      public long getStep()
      Description copied from interface: IdSegmentDistributor
      Get the step size for ID segments.

      The step size determines how many IDs are allocated in each segment. Larger steps reduce coordination overhead but may lead to ID gaps.

      Specified by:
      getStep in interface IdSegmentDistributor
      Returns:
      The step size
    • group

      public GroupedKey group()
      Specified by:
      group in interface Grouped
    • nextMaxId

      public long nextMaxId()
      Description copied from interface: IdSegmentDistributor
      Allocate the next maximum ID using the default step size.
      Specified by:
      nextMaxId in interface IdSegmentDistributor
      Returns:
      The maximum ID in the allocated range
    • nextMaxId

      public long nextMaxId(long step)
      Description copied from interface: IdSegmentDistributor
      Allocate the next maximum ID for the specified step size.

      This method allocates a new range of IDs by returning the maximum ID in the allocated range. The range starts at the previous maximum plus one and ends at the returned value.

      Specified by:
      nextMaxId in interface IdSegmentDistributor
      Parameters:
      step - The step size for allocation
      Returns:
      The maximum ID in the allocated range
    • nextIdSegment

      @Nonnull public IdSegment nextIdSegment()
      Description copied from interface: IdSegmentDistributor
      Allocate the next ID segment with infinite time-to-live.
      Specified by:
      nextIdSegment in interface IdSegmentDistributor
      Returns:
      The allocated ID segment
    • nextIdSegment

      @Nonnull public IdSegment nextIdSegment(long ttl)
      Description copied from interface: IdSegmentDistributor
      Allocate the next ID segment with the specified time-to-live.
      Specified by:
      nextIdSegment in interface IdSegmentDistributor
      Parameters:
      ttl - The time-to-live for the segment
      Returns:
      The allocated ID segment
    • nextIdSegment

      @Nonnull public IdSegment nextIdSegment(int segments, long ttl)
      Description copied from interface: IdSegmentDistributor
      Allocate the next ID segment with multiple segments and specified time-to-live.

      This method allocates a merged segment that represents multiple individual segments, useful for prefetching scenarios.

      Specified by:
      nextIdSegment in interface IdSegmentDistributor
      Parameters:
      segments - The number of segments to allocate
      ttl - The time-to-live for the segment
      Returns:
      The allocated merged ID segment
    • nextIdSegmentChain

      @Nonnull public IdSegmentChain nextIdSegmentChain(IdSegmentChain previousChain, int segments, long ttl)
      Description copied from interface: IdSegmentDistributor
      Allocate the next ID segment chain with custom configuration.

      This method allocates a new segment chain that extends the previous chain, providing the foundation for the segment chain ID generation algorithm.

      Specified by:
      nextIdSegmentChain in interface IdSegmentDistributor
      Parameters:
      previousChain - The previous segment chain
      segments - The number of segments to allocate
      ttl - The time-to-live for the segment
      Returns:
      The allocated ID segment chain
    • nextIdSegmentChain

      @Nonnull public IdSegmentChain nextIdSegmentChain(IdSegmentChain previousChain)
      Description copied from interface: IdSegmentDistributor
      Allocate the next ID segment chain with default configuration.
      Specified by:
      nextIdSegmentChain in interface IdSegmentDistributor
      Parameters:
      previousChain - The previous segment chain
      Returns:
      The allocated ID segment chain