Interface RecoverableUpdateStream<T>

Type Parameters:
T - type of the value
All Superinterfaces:
UpdateStream<T>

public interface RecoverableUpdateStream<T> extends UpdateStream<T>
An extension to 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)

Example feature use

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);
     }
 }
 
Since:
6.10
Author:
DiffusionData Limited
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.pushtechnology.diffusion.client.features.UpdateStream

    UpdateStream.Builder
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if recovery is possible following an exceptionally completed future returned from RecoverableUpdateStream.
    void
    Reestablish the inner recovery stream.

    Methods inherited from interface com.pushtechnology.diffusion.client.features.UpdateStream

    get, set, validate
  • Method Details

    • isRecoverable

      boolean isRecoverable()
      Check if recovery is possible following an exceptionally completed future returned from RecoverableUpdateStream. Must be used prior to calling recover().
      Returns:
      true if recovery is possible.
    • recover

      void recover() throws UpdateStreamRetryLimitException
      Reestablish the inner recovery stream. Deliver pending topic updates. If recoverable exceptions occur during recovery then pause and retry, where the pause duration and the maximum number of retries is governed by the 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.
      Throws:
      UpdateStreamRetryLimitException - if recovery is not possible with the limits of the retry strategy.