public final class CustomObjectBigIntegerNumberGenerator extends Base implements BigIntegerNumberGenerator
CustomObjectBigIntegerNumberGeneratorConfig
).
Execution example:
final String key = randomKey();//this could be something like "orderNumber" final CustomObjectBigIntegerNumberGeneratorConfig config = CustomObjectBigIntegerNumberGeneratorConfigBuilder.of(client(), key) .build(); final BigIntegerNumberGenerator generator = CustomObjectBigIntegerNumberGenerator.of(config); final BigInteger firstNumber = generator.getNextNumber().toCompletableFuture().join(); assertThat(firstNumber).isEqualTo(BigInteger.ONE);
See the test code.
It is possible to assign an initial value for the sequence
Execution example:
final BigInteger initialCounterValue = new BigInteger("5001"); final CustomObjectBigIntegerNumberGeneratorConfig config = CustomObjectBigIntegerNumberGeneratorConfigBuilder.of(client(), randomKey()) .container(randomKey()) .initialValue(initialCounterValue) .build(); final BigIntegerNumberGenerator generator = CustomObjectBigIntegerNumberGenerator.of(config); final BigInteger firstNumber = generator.getNextNumber().toCompletableFuture().join(); assertThat(firstNumber).isEqualTo(initialCounterValue);
See the test code.
Execution example:
final String container = randomKey(); final String key = randomKey(); final CustomObjectBigIntegerNumberGeneratorConfig config = CustomObjectBigIntegerNumberGeneratorConfigBuilder.of(client(), key) .container(container) .build(); final BigIntegerNumberGenerator generator = CustomObjectBigIntegerNumberGenerator.of(config); final BigInteger firstNumber = generator.getNextNumber().toCompletableFuture().join(); assertThat(firstNumber).isEqualTo(BigInteger.ONE); final CustomObject<BigInteger> customObject = client().executeBlocking(CustomObjectByKeyGet.of(container, key, BigInteger.class)); assertThat(customObject.getValue()).isEqualTo(BigInteger.ONE); generator.getNextNumber().toCompletableFuture().join(); final CustomObject<BigInteger> customObject2 = client().executeBlocking(CustomObjectByKeyGet.of(container, key, BigInteger.class)); assertThat(customObject2.getValue()).isEqualTo(BigInteger.valueOf(2));
See the test code.
Modifier and Type | Method and Description |
---|---|
CompletionStage<BigInteger> |
getNextNumber()
This generator ensures that all calls (even in parallel) generates a different number.
|
static CustomObjectBigIntegerNumberGenerator |
of(CustomObjectBigIntegerNumberGeneratorConfig config) |
public CompletionStage<BigInteger> getNextNumber()
BigIntegerNumberGenerator
getNextNumber
in interface BigIntegerNumberGenerator
public static CustomObjectBigIntegerNumberGenerator of(CustomObjectBigIntegerNumberGeneratorConfig config)