public RoundRobinFanIn(int n) { _n = n; Shape = new UniformFanInShape <T, T>(_n); Inlets = Shape.Ins; Out = Shape.Out; }
public MergeClosestN(int n) { if (n < 2) { throw new ArgumentException("Requires at least two streams. One primary and at least one secondary."); } _n = n; Shape = new UniformFanInShape <TIn, IImmutableList <TIn> >(_n); PrimaryInlet = Shape.Ins[0]; SecondaryInlets = Shape.Ins.Skip(1).ToImmutableList(); Out = Shape.Out; }
internal static Inlet <TIn> FindIn <TIn, TOut, T>(Builder <T> builder, UniformFanInShape <TIn, TOut> junction, int n) { var count = junction.Inlets.Count(); while (n < count) { var inlet = junction.In(n); if (builder.Module.Upstreams.ContainsKey(inlet)) { n++; } else { return(inlet); } } throw new ArgumentException("No more inlets on junction"); }
public Merge(int inputPorts, bool eagerComplete = false) { // one input might seem counter intuitive but saves us from special handling in other places if (inputPorts < 1) { throw new ArgumentException("Merge must have one or more input ports"); } _inputPorts = inputPorts; _eagerComplete = eagerComplete; var ins = ImmutableArray <Inlet <TIn> > .Empty.ToBuilder(); for (var i = 0; i < inputPorts; i++) { ins.Add(new Inlet <TIn>("Merge.in" + i)); } Out = new Outlet <TOut>("Merge.out"); Shape = new UniformFanInShape <TIn, TOut>(Out, ins.ToArray()); }
public static GraphDsl.ReverseOps <TIn, TMat> Via <TIn, TOut, TMat>(this GraphDsl.ReverseOps <TIn, TMat> ops, UniformFanInShape <TIn, TOut> junction) where TIn : TOut { var inlet = Bind(ops, junction); return(ops.Builder.To(inlet)); }
private static Inlet <TIn> Bind <TIn, TOut, TMat>(GraphDsl.ReverseOps <TIn, TMat> ops, UniformFanInShape <TIn, TOut> junction) where TIn : TOut { var b = ops.Builder; b.AddEdge(junction.Out, ops.In); return(GraphDsl.FindIn(b, junction, 0)); }
public static GraphDsl.Builder <TMat> From <TIn, TOut, TMat>(this GraphDsl.ReverseOps <TIn, TMat> ops, UniformFanInShape <TIn, TOut> junction) where TIn : TOut { Bind(ops, junction); return(ops.Builder); }
public static GraphDsl.ForwardOps <TOut2, TMat> Via <TIn, TOut1, TOut2, TMat>(this GraphDsl.ForwardOps <TOut1, TMat> ops, UniformFanInShape <TIn, TOut2> junction) where TIn : TOut1 { var b = To(ops, junction); return(b.From(junction.Out)); }
public static GraphDsl.Builder <TMat> To <TIn, TOut1, TOut2, TMat>(this GraphDsl.ForwardOps <TOut1, TMat> ops, UniformFanInShape <TIn, TOut2> junction) where TIn : TOut1 { var b = ops.Builder; var inlet = GraphDsl.FindIn(b, junction, 0); b.AddEdge(ops.Out, inlet); return(b); }
public ReverseOps <TIn, T> To <TIn, TOut>(UniformFanInShape <TIn, TOut> fanOut) { return(new ReverseOps <TIn, T>(this, FindIn(this, fanOut, 0))); }
public ForwardOps <TOut, T> From <TIn, TOut>(UniformFanInShape <TIn, TOut> fanIn) { return(new ForwardOps <TOut, T>(this, fanIn.Out)); }
public async Task RunnableGraphMadeOfBackpressuredQueueAndActorRefWithAckWorksAsExpected() { const int MAX = 4; Source <int, ISourceQueueWithComplete <int> > source = Source.Queue <int>(MAX, OverflowStrategy.Backpressure); TestProbe probe = CreateTestProbe(); Sink <IEnumerable <int>, NotUsed> sink = Sink.ActorRefWithAck <IEnumerable <int> >(probe.Ref, "init", "ack", "complete"); RunnableGraph <ISourceQueueWithComplete <int> > rg = RunnableGraph.FromGraph(GraphDsl.Create(source, sink, Keep.Left, (builder, source_, sink_) => { UniformFanOutShape <int, int> broadcaster = builder.Add(new Broadcast <int>(2)); UniformFanInShape <IEnumerable <int>, IEnumerable <int> > merger = builder.Add(new Merge <IEnumerable <int> >(2)); var f1 = Flow.Create <int>().Aggregate(new List <int>(), (agg, curr) => { agg.Add(curr); return(agg); }).Select(list => list.AsEnumerable()); var f2 = Flow.Create <int>().Aggregate(new List <int>(), (agg, curr) => { agg.Add(curr); return(agg); }).Select(list => list.AsEnumerable()); builder.From(source_).To(broadcaster.In); builder.From(broadcaster.Out(0)).Via(f1).To(merger.In(0)); builder.From(broadcaster.Out(1)).Via(f2).To(merger.In(1)); builder.From(merger.Out).To(sink_); return(ClosedShape.Instance); })); ISourceQueueWithComplete <int> q = rg.Run(_materializer); probe.ExpectMsg <string>((msg, sender) => { if (msg != "init") { throw new InvalidOperationException($"Expected: init. Found: {msg}"); } sender.Tell("ack"); }); await q.OfferAsync(2); await q.OfferAsync(4); await q.OfferAsync(8); await q.OfferAsync(16); q.Complete(); await q.WatchCompletionAsync(); probe.ExpectMsg <IEnumerable <int> >((msg, sender) => { Assert.Equal(new[] { 2, 4, 8, 16 }.AsEnumerable(), msg); sender.Tell("ack"); }); probe.ExpectMsg <IEnumerable <int> >((msg, sender) => { Assert.Equal(new[] { 2, 4, 8, 16 }.AsEnumerable(), msg); sender.Tell("ack"); }); probe.ExpectMsg("complete"); probe.ExpectNoMsg(); }