示例#1
0
 /// <summary>
 /// Converts this Flow to a <see cref="IRunnableGraph{TMat}"/> that materializes to a Reactive Streams <see cref="IProcessor{T1,T2}"/>
 /// which implements the operations encapsulated by this Flow. Every materialization results in a new Processor
 /// instance, i.e. the returned <see cref="IRunnableGraph{TMat}"/> is reusable.
 /// </summary>
 /// <returns>A <see cref="IRunnableGraph{TMat}"/> that materializes to a <see cref="IProcessor{T1,T2}"/> when Run() is called on it.</returns>
 public IRunnableGraph <IProcessor <TIn, TOut> > ToProcessor()
 => Source.AsSubscriber <TIn>()
 .Via(this)
 .ToMaterialized(Sink.AsPublisher <TOut>(false), Keep.Both)
 .MapMaterializedValue(t => new FlowProcessor <TIn, TOut>(t.Item1, t.Item2) as IProcessor <TIn, TOut>);
示例#2
0
        /// <summary>
        ///  Materializes this Source immediately.
        /// </summary>
        /// <param name="materializer">The materializer.</param>
        /// <returns>A tuple containing the (1) materialized value and (2) a new <see cref="Source"/>
        ///  that can be used to consume elements from the newly materialized <see cref="Source"/>.</returns>
        public Tuple <TMat, Source <TOut, NotUsed> > PreMaterialize(IMaterializer materializer)
        {
            var tup = ToMaterialized(Sink.AsPublisher <TOut>(fanout: true), Keep.Both).Run(materializer);

            return(Tuple.Create(tup.Item1, Source.FromPublisher(tup.Item2)));
        }
示例#3
0
 //private readonly IRunnableGraph<(UniqueKillSwitch, ISinkQueue<T>)> _graph;
 public StreamsAsyncEnumerableRerunnable(Source <T, TMat> source, IMaterializer materializer)
 {
     _source       = source;
     _materializer = materializer;
     thisSinkQueue = defaultSinkqueue;
 }
示例#4
0
 /// <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);
示例#5
0
 /// <summary>
 /// Creates a <see cref="Source{TOut,TMat}"/> which when materialized will return an <see cref="Stream"/> which it is possible
 /// to write the ByteStrings to the stream this Source is attached to.
 ///
 /// This Source is intended for inter-operation with legacy APIs since it is inherently blocking.
 ///
 /// You can configure the default dispatcher for this Source by changing the "akka.stream.blocking-io-dispatcher" or
 /// set it for a given Source by using <see cref="ActorAttributes.CreateDispatcher"/>.
 ///
 /// The created <see cref="Stream"/> will be closed when the <see cref="Source{TOut,TMat}"/> is cancelled, and closing the <see cref="Stream"/>
 /// will complete this <see cref="Source{TOut,TMat}"/>.
 /// </summary>
 /// <param name="writeTimeout">The max time the write operation on the materialized OutputStream should block, defaults to 5 seconds</param>
 /// <returns>TBD</returns>
 public static Source <ByteString, Stream> AsOutputStream(TimeSpan?writeTimeout = null)
 => Source.FromGraph(new OutputStreamSourceStage(writeTimeout ?? TimeSpan.FromSeconds(5)));
示例#6
0
 /// <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);
示例#7
0
 /// <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>
 /// <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> OnFailuresWithBackoff <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, true, maxRestarts));
示例#8
0
 /// <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>
 public static Source <T, NotUsed> WithBackoff <T, TMat>(Func <Source <T, TMat> > sourceFactory, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor)
 => Source.FromGraph(new RestartWithBackoffSource <T, TMat>(sourceFactory, minBackoff, maxBackoff, randomFactor, false, int.MaxValue));
示例#9
0
            protected override void StartGraph()
            {
                var sourceOut = CreateSubOutlet(_stage.In);

                Source.FromGraph(sourceOut.Source).RunWith(_stage.SinkFactory(), SubFusingMaterializer);
            }