Ejemplo n.º 1
0
        public ChangeTrackerActor()
        {
            var mat = Context.Materializer();

            var(queue, source) = Source.Queue <AppInfo>(10, OverflowStrategy.DropHead).PreMaterialize(mat);

            _appInfos = queue;

            var hub = source.ToMaterialized(BroadcastHub.Sink <AppInfo>(), Keep.Right);


            Receive <QueryChangeSource>("QueryChanedSource", (changeSource, reporter) => reporter.Compled(OperationResult.Success(new AppChangedSource(hub.Run(mat)))));
            Receive <AppInfo>(ai => _appInfos.OfferAsync(ai).PipeTo(Self));
            Receive <IQueueOfferResult>(r =>
            {
                switch (r)
                {
                case QueueOfferResult.Failure f:
                    Log.Error(f.Cause, "Error In Change Tracker");
                    break;

                case QueueOfferResult.QueueClosed _:
                    Log.Warning("Unexpectem Tracker Queue Close.");
                    break;
                }
            });
        }
Ejemplo n.º 2
0
        public ChannelAdjuster(IEnumerable <ChannelAdjusterConfig> configs, IActorRef target)
        {
            _configs = configs;

            /* Receives the first sample and creates the graph. Starts the graph and
             * transitions to running state and passes the sample back in as the
             * first message.
             */
            Receive <ChannelData <float> >(sample =>
            {
                //Create the graph from the first sample and then become working.
                Stash.Stash();
                var runnableGraph = CreateGraph(target, _configs.ToList(), sample);
                _queue            = runnableGraph.Run(Context.Materializer());
                Become(Working);
            });
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 public sealed record ChangeTrackeState(ActorMaterializer Materializer, ISourceQueueWithComplete <AppInfo> AppInfos, IRunnableGraph <Source <AppInfo, NotUsed> > Hub);