Interface IdGenerator<T>
- Type Parameters:
T- the type of identifier produced
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Request identifiers of a particular type (for example, sequential Long values, random UUIDs, etc.)
Useful for incorporating request data in nonlocal deployment environments (e.g. a tracing header like X-Amzn-Trace-Id).
Implementations may or may not guarantee uniqueness, ordering, or repeatability of generated identifiers. Callers should not assume any such guarantees unless documented by the implementation.
Standard threadsafe implementations can be acquired via these factory methods:
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull IdGenerator<String> Acquires a threadsafeIdGeneratorwith a best-effort local IP prefix.static @NonNull IdGenerator<String> fromPrefix(@NonNull String prefix) Acquires a threadsafeIdGeneratorwith the given prefix.generateId(@NonNull Request request) Generates an identifier for the givenRequest.
-
Method Details
-
generateId
Generates an identifier for the givenRequest.Implementations may choose different strategies (sequential, random, host-based, etc.) and are not required to guarantee uniqueness unless explicitly documented.
Implementations may choose to incorporate request data (e.g. a tracing header like
X-Amzn-Trace-Id).- Parameters:
request- the request for which an identifier is being generated- Returns:
- the generated identifier (never
null)
-
defaultInstance
Acquires a threadsafeIdGeneratorwith a best-effort local IP prefix.This method is guaranteed to return a new instance.
- Returns:
- an
IdGeneratorwith default settings
-
fromPrefix
Acquires a threadsafeIdGeneratorwith the given prefix.This method is guaranteed to return a new instance.
- Parameters:
prefix- a string to prepend to the generated numeric ID- Returns:
- an
IdGeneratorconfigured with the given prefix
-