java.lang.Object
me.ahoo.cosid.internal.GeneratorEntry
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescription<T> TThe first view that is atype.voidclose()Closes the generator; a disabled one has nothing to close, and a user one is left to its owner.static GeneratorEntrycosId80(TimeBasedGenerator generator, PartsCodec codec, SlotHandle slot, String machine, String machineNamespace, LongAdder counter) An 80-bit CosId generator: parts and text ids only.static GeneratorEntrycustom(String name, IdGenerator ids, IdCodec codec, LongAdder counter) A user generator (GeneratorSpec.CustomorInstance, D41): the runtime hands it out but does not own it, so closing the entry leaves it open.static GeneratorEntryA disabled generator (D24): every lookup throwsGeneratorDisabledException.The ids issued through the views so far.ids()Thelongids.info()What describe() tells about this generator.booleanmachine()The machine a time-based generator issues on.name()static GeneratorEntryperiodic(PeriodicSegmentGenerator generator, GroupedCodec codec, String store, Map<String, Object> details, LongAdder counter) A periodic segment generator: grouped ids only.static GeneratorEntrysegment(SegmentGenerator generator, IdCodec codec, String store, LongAdder counter) A segment generator.static GeneratorEntrysnowflake(TimeBasedGenerator generator, IdCodec codec, SlotHandle slot, String machine, String machineNamespace, LongAdder counter) A Snowflake generator.strategy()strings()Thelongids with the codec.text()The text ids of any strategy: the codec of thelongid, the parts codec or the grouped codec.The time-based generator, to close it first and read its last issued time.static GeneratorEntryuuidV7(String name, TimeSource time, LongAdder counter) A UUIDv7 generator (D46): nolongids; its text is the canonical form.
-
Field Details
-
SNOWFLAKE
- See Also:
-
COSID80
- See Also:
-
SEGMENT
- See Also:
-
PERIODIC_SEGMENT
- See Also:
-
CUSTOM
- See Also:
-
UUIDV7
- See Also:
-
-
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 generatorcodec- its codecslot- the slot it issues onmachine- the name of the machine of the slotmachineNamespace- the namespace of the machinecounter- 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 generatorcodec- its parts codecslot- the slot it issues onmachine- the name of the machine of the slotmachineNamespace- the namespace of the machinecounter- 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 generatorcodec- its codecstore- the store namecounter- 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 generatorcodec- its grouped codecstore- the store namedetails- what describe() tells besides the current periodcounter- counts the ids issued; null for none- Returns:
- the entry
-
custom
A user generator (GeneratorSpec.CustomorInstance, D41): the runtime hands it out but does not own it, so closing the entry leaves it open.- Parameters:
name- the generator nameids- the user generatorcodec- its codeccounter- counts the ids issued; null for none- Returns:
- the entry
-
uuidV7
A UUIDv7 generator (D46): nolongids; 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 nametime- the time sourcecounter- counts the ids, or null- Returns:
- the entry
-
disabled
A disabled generator (D24): every lookup throwsGeneratorDisabledException.- Parameters:
name- the generator namestrategy- the strategy it would havestore- the store it would use, empty for none- Returns:
- the entry
-
machine
The machine a time-based generator issues on.- Returns:
- the machine name; empty for other strategies
-
generated
The ids issued through the views so far.- Returns:
- the count; empty when not counting or disabled
-
name
-
strategy
-
isDisabled
public boolean isDisabled() -
timeBased
The time-based generator, to close it first and read its last issued time.- Returns:
- the generator, or empty for other strategies
-
ids
Thelongids.- Returns:
- the generator
- Throws:
GeneratorDisabledException- if the generator is disabledNoSuchElementException- if it issues nolongids
-
strings
Thelongids with the codec.- Returns:
- the generator
- Throws:
GeneratorDisabledException- if the generator is disabledNoSuchElementException- if it issues nolongids
-
text
The text ids of any strategy: the codec of thelongid, the parts codec or the grouped codec.- Returns:
- the text ids
- Throws:
GeneratorDisabledException- if the generator is disabled
-
as
The first view that is atype.- Type Parameters:
T- the wanted type- Parameters:
type- the wanted type- Returns:
- the view
- Throws:
GeneratorDisabledException- if the generator is disabledNoSuchElementException- if no view is atype
-
info
What describe() tells about this generator.- Returns:
- the info
-
close
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
-