Overview
Sequence Generator is used to create unique primary key values, replace missing primary keys, or cycle through a sequential range of numbers. In Etlworks the sequence numbers can be generated programmatically using one of the available sequence generators.
UniqueNumber
This class allows developers to generate a timestamp-based unique and sequential long number. The actual number is generated using the following algorithm:
(System.currentTimeMillis() << 20) + n
, where n is incremented by 1 on each call.
The same instance of the UniqueNumber class must be used to generate the consistently incremented sequence.
How to use UniqueNumber
var uniqueNumber = etlConfig.getValue("uniqueNumber");
if (uniqueNumber == null) {
uniqueNumber = new com.toolsverse.util.UniqueNumber();
etlConfig.setValue("uniqueNumber", uniqueNumber);
}
value = uniqueNumber.nextNumber();
RedisSequenceGenerator
The instance of this class uses Redis to generate the unique sequential numbers so it can be used simultaneously by multiple flows. The class makes a call to the Redis each time it needs to generate a new number. It can generate up to 10K numbers per second.
How to use RedisSequenceGenerator
com.toolsverse.io.RedisSequenceGenerator.instance().nextNumber(key, startValue);
where the key
is any string, for example, table name and the startValue
is a starting sequence number, which can be any not negative long number.
Example
var seq = com.toolsverse.io.RedisSequenceGenerator.instance().nextNumber('my_table_name', 1);
Comments
0 comments
Please sign in to leave a comment.