public class PseudoRandomIdGenerator extends java.lang.Object implements IdGenerator
The ID is generated from the a combination of Random.nextBytes(byte[]) (8 bytes, and then base64 encoded),
along with the configured prefix to generate an id. No guarantees are made for the uniqueness of the id that is generated. If you
wish for a unique-id then you should consider using GuidGenerator
instead.
Effectively the ID that is generated follows the form
ID = prefix unique-sequence
prefix = *VCHAR
unique sequence = 12(ALPHA/DIGIT/"+"/"/"/"=")
If you wish to restrict the length of the resulting ID, then bear in mind that with padding 8 bytes base64 encoded is 12 characters long so consider how long your prefix is.
In the adapter configuration file this class is aliased as pseudo-random-id-generator which is the preferred alternative to the fully qualified classname when building your configuration.
Constructor and Description |
---|
PseudoRandomIdGenerator() |
PseudoRandomIdGenerator(java.lang.String prefix) |
PseudoRandomIdGenerator(java.lang.String prefix,
boolean useSecureRandom) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
create(java.lang.Object msg)
A generated ID.
|
java.lang.String |
getPrefix() |
java.lang.Boolean |
getUseSecureRandom() |
void |
setPrefix(java.lang.String s) |
void |
setUseSecureRandom(java.lang.Boolean u)
Whether or not to use
SecureRandom when generating a random sequence of bytes. |
public PseudoRandomIdGenerator()
public PseudoRandomIdGenerator(java.lang.String prefix)
public PseudoRandomIdGenerator(java.lang.String prefix, boolean useSecureRandom)
public java.lang.String create(java.lang.Object msg)
create
in interface IdGenerator
msg
- the object to create an id aroundpublic java.lang.String getPrefix()
public void setPrefix(java.lang.String s)
s
- the separator to setpublic java.lang.Boolean getUseSecureRandom()
public void setUseSecureRandom(java.lang.Boolean u)
SecureRandom
when generating a random sequence of bytes.u
- the useSecureRandom to set, if not set, defaults to true.