/// <summary> /// Wrap the given <see cref="Source"/> with a <see cref="Source"/> that will restart it when it fails or complete using an exponential /// backoff. /// This <see cref="Source"/> will never emit a complete or failure, since the completion or failure of the wrapped <see cref="Source"/> /// is always handled by restarting it. The wrapped <see cref="Source"/> can however be cancelled by cancelling this <see cref="Source"/>. /// When that happens, the wrapped <see cref="Source"/>, if currently running will be cancelled, and it will not be restarted. /// This can be triggered simply by the downstream cancelling, or externally by introducing a <see cref="IKillSwitch"/> right /// after this <see cref="Source"/> in the graph. /// This uses the same exponential backoff algorithm as <see cref="Akka.Pattern.Backoff"/>. /// </summary> /// <param name="sourceFactory">A factory for producing the <see cref="Source"/> to wrap.</param> /// <param name="minBackoff">Minimum (initial) duration until the child actor will started again, if it is terminated</param> /// <param name="maxBackoff">The exponential back-off is capped to this duration</param> /// <param name="randomFactor">After calculation of the exponential back-off an additional random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. In order to skip this additional delay pass in `0`.</param> /// <param name="maxRestarts">The amount of restarts is capped to this amount within a time frame of minBackoff. Passing `0` will cause no restarts and a negative number will not cap the amount of restarts.</param> public static Source <T, NotUsed> WithBackoff <T, TMat>(Func <Source <T, TMat> > sourceFactory, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor, int maxRestarts) => Source.FromGraph(new RestartWithBackoffSource <T, TMat>(sourceFactory, minBackoff, maxBackoff, randomFactor, false, maxRestarts));
protected override void StartGraph() { var sourceOut = CreateSubOutlet(_stage.In); Source.FromGraph(sourceOut.Source).RunWith(_stage.SinkFactory(), SubFusingMaterializer); }
/// <summary> /// Connect this <see cref="Sink{TIn,TMat}"/> to a <see cref="Source{T,TMat}"/> and run it. The returned value is the materialized value /// of the <see cref="Source{T,TMat}"/>, e.g. the <see cref="ISubscriber{T}"/>. /// </summary> /// <typeparam name="TMat2">TBD</typeparam> /// <param name="source">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public TMat2 RunWith <TMat2>(IGraph <SourceShape <TIn>, TMat2> source, IMaterializer materializer) => Source.FromGraph(source).To(this).Run(materializer);
/// <summary> /// Wrap the given <see cref="Source"/> with a <see cref="Source"/> that will restart it when it fails using an exponential backoff. /// This <see cref="Source"/> will never emit a failure, since the failure of the wrapped <see cref="Source"/> is always handled by /// restarting. The wrapped <see cref="Source"/> can be cancelled by cancelling this <see cref="Source"/>. /// When that happens, the wrapped <see cref="Source"/>, if currently running will be cancelled, and it will not be restarted. /// This can be triggered simply by the downstream cancelling, or externally by introducing a <see cref="IKillSwitch"/> right /// after this <see cref="Source"/> in the graph. /// This uses the same exponential backoff algorithm as <see cref="Akka.Pattern.Backoff"/>. /// </summary> /// <param name="sourceFactory">A factory for producing the <see cref="Source"/> to wrap.</param> /// <param name="minBackoff">Minimum (initial) duration until the child actor will started again, if it is terminated</param> /// <param name="maxBackoff">The exponential back-off is capped to this duration</param> /// <param name="randomFactor">After calculation of the exponential back-off an additional random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. In order to skip this additional delay pass in `0`.</param> public static Source <T, NotUsed> OnFailuresWithBackoff <T, TMat>(Func <Source <T, TMat> > sourceFactory, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor) => Source.FromGraph(new RestartWithBackoffSource <T, TMat>(sourceFactory, minBackoff, maxBackoff, randomFactor, true, int.MaxValue));
public static Source <T, Task <ISinkRef <T> > > SinkRef <T>() => Source.FromGraph <T, Task <ISinkRef <T> > >(new SourceRefStageImpl <T>(null));
/// <summary> /// Connect the <see cref="Source{TOut,TMat1}"/> to this <see cref="Flow{TIn,TOut,TMat}"/> and then connect it to the <see cref="Sink{TIn,TMat2}"/> and run it. /// The returned tuple contains the materialized values of the <paramref name="source"/> and <paramref name="sink"/>, e.g. the <see cref="ISubscriber{T}"/> /// of a <see cref="Source.AsSubscriber{T}"/> and <see cref="IPublisher{T}"/> of a <see cref="Sink.Publisher{TIn}"/>. /// </summary> /// <typeparam name="TMat1">TBD</typeparam> /// <typeparam name="TMat2">TBD</typeparam> /// <param name="source">TBD</param> /// <param name="sink">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public Tuple <TMat1, TMat2> RunWith <TMat1, TMat2>(IGraph <SourceShape <TIn>, TMat1> source, IGraph <SinkShape <TOut>, TMat2> sink, IMaterializer materializer) => Source.FromGraph(source).Via(this).ToMaterialized(sink, Keep.Both).Run(materializer);