T - type of the valuepublic interface RecoverableUpdateStream<T> extends UpdateStream<T>
UpdateStream that includes recovery functionality.
A recoverable update stream wraps an UpdateStream, tracking topic
updates and associated CompletableFutures.
In the event that a RecoverableUpdateStream returns a CompletableFuture
that completes exceptionally, calling isRecoverable()
returns true recovery is possible.
Call recover() to re-establish the update stream and re-play
incomplete topic updates before resuming.
Construct a RecoverableUpdateStream using
UpdateStream.Builder.build(String, Class, RetryStrategy)
This example demonstrates use of a RecoverableUpdateStream to update topic
my/topic with 1000 unique values, after which it checks for
failure in any of them. If any topic updates complete exceptionally and the
exception is recoverable, the code recovers - reestablishing an UpdateStream
and delivering the failed topic updates.
final TopicSpecification topicSpec =
Diffusion.newTopicSpecification(TopicType.STRING);
final RecoverableUpdateStream<String> updateStream =
session.feature(TopicUpdate.class)
.newUpdateStreamBuilder()
.specification(topicSpec)
.build("my/topic",
String.class,
new RetryStrategy(1_000, 10));
final CompletableFuture[] cfs = IntStream
.range(0, 1000)
.mapToObj(i -> updateStream.set("Value of " + i))
.toArray(CompletableFuture[]::new);
try {
allOf(cfs).get();
}
catch(CancellationException | ExecutionException | InterruptedException ex ) {
if (updateStream.isRecoverable()) {
updateStream.recover();
}
else {
LOG.error("Cannot recover", ex);
}
}
UpdateStream.Builder| Modifier and Type | Method and Description |
|---|---|
boolean |
isRecoverable()
Check if recovery is possible following an exceptionally completed future returned from
RecoverableUpdateStream. |
void |
recover()
Reestablish the inner recovery stream.
|
get, set, validateboolean isRecoverable()
RecoverableUpdateStream.
Must be used prior to calling recover().void recover()
throws UpdateStreamRetryLimitException
RetryStrategy supplied to builder function
UpdateStream.Builder.build(String, Class, RetryStrategy).
If non-recoverable errors occur during recovery then recovery is aborted.
If recovery fails for any reason then further recovery attempts will fail.UpdateStreamRetryLimitException - if recovery is not possible with
the limits of the retry strategy.Copyright © 2025 DiffusionData Limited. All rights reserved.