Class GeneratorEntry

java.lang.Object
me.ahoo.cosid.internal.GeneratorEntry

public final class GeneratorEntry extends Object
A generator of a runtime with the views its lookups hand out: its long, int, parts or grouped ids, its codec, its text ids and the generator itself. With a counter (RuntimeOptions.countGenerated) every view but the concrete generator counts the ids it issues; without one the views are the generator itself, so the hot path is unchanged.
  • Field Details

  • Method Details

    • snowflake

      public static GeneratorEntry snowflake(TimeBasedGenerator generator, IdCodec codec, SlotHandle slot, String machine, String machineNamespace, LongAdder counter)
      A Snowflake generator.
      Parameters:
      generator - the generator
      codec - its codec
      slot - the slot it issues on
      machine - the name of the machine of the slot
      machineNamespace - the namespace of the machine
      counter - counts the ids issued; null for none
      Returns:
      the entry
    • cosId80

      public static GeneratorEntry cosId80(TimeBasedGenerator generator, PartsCodec codec, SlotHandle slot, String machine, String machineNamespace, LongAdder counter)
      An 80-bit CosId generator: parts and text ids only.
      Parameters:
      generator - the generator
      codec - its parts codec
      slot - the slot it issues on
      machine - the name of the machine of the slot
      machineNamespace - the namespace of the machine
      counter - counts the ids issued; null for none
      Returns:
      the entry
    • segment

      public static GeneratorEntry segment(SegmentGenerator generator, IdCodec codec, String store, LongAdder counter)
      A segment generator.
      Parameters:
      generator - the generator
      codec - its codec
      store - the store name
      counter - counts the ids issued; null for none
      Returns:
      the entry
    • periodic

      public static GeneratorEntry periodic(PeriodicSegmentGenerator generator, GroupedCodec codec, String store, Map<String,Object> details, LongAdder counter)
      A periodic segment generator: grouped ids only.
      Parameters:
      generator - the generator
      codec - its grouped codec
      store - the store name
      details - what describe() tells besides the current period
      counter - counts the ids issued; null for none
      Returns:
      the entry
    • custom

      public static GeneratorEntry custom(String name, IdGenerator ids, IdCodec codec, LongAdder counter)
      A user generator (GeneratorSpec.Custom or Instance, D41): the runtime hands it out but does not own it, so closing the entry leaves it open.
      Parameters:
      name - the generator name
      ids - the user generator
      codec - its codec
      counter - counts the ids issued; null for none
      Returns:
      the entry
    • uuidV7

      public static GeneratorEntry uuidV7(String name, TimeSource time, LongAdder counter)
      A UUIDv7 generator (D46): no long ids; its text is the canonical form. The one generator of the entry counts its ids itself, whichever view issues them (text(name), the generator by its type, a Spring bean; R2-uuid-01), and ends with the runtime as the other strategies do (R2-uuid-03): both through its time source, read once per id.
      Parameters:
      name - the generator name
      time - the time source
      counter - counts the ids, or null
      Returns:
      the entry
    • disabled

      public static GeneratorEntry disabled(String name, String strategy, String store)
      A disabled generator (D24): every lookup throws GeneratorDisabledException.
      Parameters:
      name - the generator name
      strategy - the strategy it would have
      store - the store it would use, empty for none
      Returns:
      the entry
    • machine

      public Optional<String> machine()
      The machine a time-based generator issues on.
      Returns:
      the machine name; empty for other strategies
    • generated

      public OptionalLong generated()
      The ids issued through the views so far.
      Returns:
      the count; empty when not counting or disabled
    • name

      public String name()
    • strategy

      public String strategy()
    • isDisabled

      public boolean isDisabled()
    • timeBased

      public Optional<TimeBasedGenerator> timeBased()
      The time-based generator, to close it first and read its last issued time.
      Returns:
      the generator, or empty for other strategies
    • ids

      public IdGenerator ids()
      The long ids.
      Returns:
      the generator
      Throws:
      GeneratorDisabledException - if the generator is disabled
      NoSuchElementException - if it issues no long ids
    • strings

      public StringIdGenerator strings()
      The long ids with the codec.
      Returns:
      the generator
      Throws:
      GeneratorDisabledException - if the generator is disabled
      NoSuchElementException - if it issues no long ids
    • text

      public Supplier<String> text()
      The text ids of any strategy: the codec of the long id, the parts codec or the grouped codec.
      Returns:
      the text ids
      Throws:
      GeneratorDisabledException - if the generator is disabled
    • as

      public <T> T as(Class<T> type)
      The first view that is a type.
      Type Parameters:
      T - the wanted type
      Parameters:
      type - the wanted type
      Returns:
      the view
      Throws:
      GeneratorDisabledException - if the generator is disabled
      NoSuchElementException - if no view is a type
    • info

      public GeneratorInfo info()
      What describe() tells about this generator.
      Returns:
      the info
    • close

      public void close() throws Exception
      Closes the generator; a disabled one has nothing to close, and a user one is left to its owner.
      Throws:
      Exception - if the generator fails to close