Class IdSegmentDistributor.Atomic

java.lang.Object
me.ahoo.cosid.segment.IdSegmentDistributor.Atomic
All Implemented Interfaces:
Grouped, IdSegmentDistributor
Enclosing interface:
IdSegmentDistributor

public static class IdSegmentDistributor.Atomic extends Object implements IdSegmentDistributor
Atomic implementation of IdSegmentDistributor for testing purposes.

This implementation uses atomic operations to allocate ID segments, making it suitable for single-instance scenarios or testing.

  • Constructor Details

    • Atomic

      public Atomic()
      Create a new Atomic distributor with default step size.
    • Atomic

      public Atomic(long step)
      Create a new Atomic distributor with custom step size.
      Parameters:
      step - The step size for ID segments
  • Method Details

    • getNamespace

      @Nonnull public String getNamespace()
      Get the namespace for this distributor.
      Specified by:
      getNamespace in interface IdSegmentDistributor
      Returns:
      The namespace
    • getName

      @Nonnull public String getName()
      Get the name for this distributor.
      Specified by:
      getName in interface IdSegmentDistributor
      Returns:
      The name
    • getStep

      public long getStep()
      Get the step size for ID segments.
      Specified by:
      getStep in interface IdSegmentDistributor
      Returns:
      The step size
    • nextMaxId

      public long nextMaxId(long step)
      Allocate the next maximum ID for the specified step size.
      Specified by:
      nextMaxId in interface IdSegmentDistributor
      Parameters:
      step - The step size for allocation
      Returns:
      The maximum ID in the allocated range