Interface Sinks.EmitFailureHandler

Enclosing class:
Sinks

public static interface Sinks.EmitFailureHandler
A handler supporting the emit API (eg. Sinks.Many.emitNext(Object, Sinks.EmitFailureHandler)), checking non-successful emission results from underlying tryEmit API calls to decide whether or not such calls should be retried. Other than instructing to retry, the handlers are allowed to have side effects like parking the current thread for longer retry loops. They don't, however, influence the exact action taken by the emit API implementations when the handler doesn't allow the retry to occur.
Implementation Note:
It is expected that the handler may perform side effects (e.g. busy looping) and should not be considered a plain Predicate.
  • Field Details

    • FAIL_FAST

      static final Sinks.EmitFailureHandler FAIL_FAST
      A pre-made handler that will not instruct to retry any failure and trigger the failure handling immediately.
  • Method Details

    • busyLooping

      static Sinks.EmitFailureHandler busyLooping(Duration duration)
      Create an Sinks.EmitFailureHandler which will busy loop in case of concurrent use of the sink (Sinks.EmitResult.FAIL_NON_SERIALIZED, up to a deadline. The deadline is computed immediately from the current time (construction time) + provided Duration.

      As a result there will always be some delay between this computation and the actual first use of the handler (at a minimum, the time it takes for the first sink emission attempt). Consider this when choosing the Duration, and probably prefer something above 100ms, and don't cache the returning handler for later usage.

      Parameters:
      duration - Duration for the deadline
      Returns:
      an optimistic and bounded busy-looping Sinks.EmitFailureHandler
    • onEmitFailure

      boolean onEmitFailure(SignalType signalType, Sinks.EmitResult emitResult)
      Decide whether the emission should be retried, depending on the provided Sinks.EmitResult and the type of operation that was attempted (represented as a SignalType). Side effects are allowed.
      Parameters:
      signalType - the signal that triggered the emission. Can be either SignalType.ON_NEXT, SignalType.ON_ERROR or SignalType.ON_COMPLETE.
      emitResult - the result of the emission (a failure)
      Returns:
      true if the operation should be retried, false otherwise.