コード例 #1
0
ファイル: InterpreterBenchmark.cs プロジェクト: ziez/akka.net
        private static void Execute(int numberOfIdentities)
        {
            new GraphInterpreterSpecKit().WithTestSetup((setup, lastEvents) =>
            {
                var identities =
                    Enumerable.Range(1, numberOfIdentities)
                    .Select(_ => GraphStages.Identity <int>())
                    .Cast <IGraphStageWithMaterializedValue <Shape, object> >()
                    .ToArray();

                var source = new GraphDataSource <int>("source", Data100K);
                var sink   = new GraphDataSink <int>("sink", Data100K.Length);

                var b = setup.Builder(identities)
                        .Connect(source, identities[0].Shape.Inlets[0] as Inlet <int>)
                        .Connect(identities.Last().Shape.Outlets[0] as Outlet <int>, sink);

                // FIXME: This should not be here, this is pure setup overhead
                for (var i = 0; i < identities.Length - 1; i++)
                {
                    b.Connect(identities[i].Shape.Outlets[0] as Outlet <int>,
                              identities[i + 1].Shape.Inlets[0] as Inlet <int>);
                }

                b.Init();
                sink.RequestOne();
                setup.Interpreter.Execute(int.MaxValue);
            });
        }
コード例 #2
0
 public GraphInterpreterSpec(ITestOutputHelper output = null) : base(output)
 {
     _identity  = GraphStages.Identity <int>();
     _detach    = new Detacher <int>();
     _zip       = new Zip <int, string>();
     _broadcast = new Broadcast <int>(2);
     _merge     = new Merge <int>(2);
     _balance   = new Balance <int>(2);
 }
コード例 #3
0
        public override IProcessor <int?, int?> CreateIdentityProcessor(int bufferSize)
        {
            var settings     = ActorMaterializerSettings.Create(System).WithInputBuffer(bufferSize / 2, bufferSize);
            var materializer = ActorMaterializer.Create(System, settings);

            // withAttributes "wraps" the underlying identity and protects it from automatic removal
            return(Flow.Create <int?>()
                   .Via(GraphStages.Identity <int?>())
                   .Named("identity")
                   .ToProcessor()
                   .Run(materializer));
        }
コード例 #4
0
        /// <summary>
        /// Transform this <see cref="Source{TOut,TMat}"/> by appending the given processing steps.
        /// The <paramref name="combine"/> function is used to compose the materialized values of this flow and that
        /// flow into the materialized value of the resulting Flow.
        /// </summary>
        /// <typeparam name="TOut2">TBD</typeparam>
        /// <typeparam name="TMat2">TBD</typeparam>
        /// <typeparam name="TMat3">TBD</typeparam>
        /// <param name="flow">TBD</param>
        /// <param name="combine">TBD</param>
        /// <returns>TBD</returns>
        public Source <TOut2, TMat3> ViaMaterialized <TOut2, TMat2, TMat3>(IGraph <FlowShape <TOut, TOut2>, TMat2> flow, Func <TMat, TMat2, TMat3> combine)
        {
            if (flow.Module == GraphStages.Identity <TOut2>().Module)
            {
                return(this as Source <TOut2, TMat3>);
            }

            var flowCopy = flow.Module.CarbonCopy();

            return(new Source <TOut2, TMat3>(Module
                                             .Fuse(flowCopy, Shape.Outlet, flowCopy.Shape.Inlets.First(), combine)
                                             .ReplaceShape(new SourceShape <TOut2>((Outlet <TOut2>)flowCopy.Shape.Outlets.First()))));
        }
コード例 #5
0
        public void A_Graph_should_suitably_override_attribute_handling_methods()
        {
            var ga = GraphDsl.Create(b =>
            {
                var id = b.Add(GraphStages.Identity <int>());
                return(new FlowShape <int, int>(id.Inlet, id.Outlet));
            }).Async().AddAttributes(Attributes.None).Named("useless");

            ga.Module.Attributes.GetFirstAttribute <Attributes.Name>().Value.Should().Be("useless");
            ga.Module.Attributes.GetFirstAttribute <Attributes.AsyncBoundary>()
            .Should()
            .Be(Attributes.AsyncBoundary.Instance);
        }
コード例 #6
0
        public void ActorGraphInterpreter_should_be_able_to_interpret_a_simple_identity_graph_stage()
        {
            this.AssertAllStagesStopped(() =>
            {
                var identity = GraphStages.Identity <int>();

                var task = Source.From(Enumerable.Range(1, 100))
                           .Via(identity)
                           .Grouped(200)
                           .RunWith(Sink.First <IEnumerable <int> >(), Materializer);

                task.AwaitResult().Should().Equal(Enumerable.Range(1, 100));
            }, Materializer);
        }
コード例 #7
0
        public void ActorGraphInterpreter_should_be_able_to_reuse_a_simple_identity_graph_stage()
        {
            this.AssertAllStagesStopped(() =>
            {
                var identity = GraphStages.Identity <int>();

                var task = Source.From(Enumerable.Range(1, 100))
                           .Via(identity)
                           .Via(identity)
                           .Via(identity)
                           .Grouped(200)
                           .RunWith(Sink.First <IEnumerable <int> >(), _materializer);

                task.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
                task.Result.Should().Equal(Enumerable.Range(1, 100));
            }, _materializer);
        }
コード例 #8
0
        private void Execute(ActorMaterializer actorMaterializer, int numberOfSelectOps, bool useGraphStageIdentity)
        {
            var syncTestPublisher = new SyncTestPublisher();

            var flow = MakeSelects(Source.FromPublisher(syncTestPublisher), numberOfSelectOps, () =>
            {
                if (useGraphStageIdentity)
                {
                    return(GraphStages.Identity <int>());
                }
                return(Flow.Create <int>().Select(x => x));
            });

            var l = new AtomicBoolean();

            flow.RunWith(Sink.OnComplete <int>(() => l.Value = true, _ => { }), actorMaterializer);

            while (!l.Value)
            {
                Thread.Sleep(10);
            }
        }
コード例 #9
0
ファイル: Source.cs プロジェクト: yyp2003net/akka.net
        /// <summary>
        /// Transform this <see cref="Source{TOut,TMat}"/> by appending the given processing steps.
        /// The <paramref name="combine"/> function is used to compose the materialized values of this flow and that
        /// flow into the materialized value of the resulting Flow.
        /// </summary>
        /// <typeparam name="TOut2">TBD</typeparam>
        /// <typeparam name="TMat2">TBD</typeparam>
        /// <typeparam name="TMat3">TBD</typeparam>
        /// <param name="flow">TBD</param>
        /// <param name="combine">TBD</param>
        /// <returns>TBD</returns>
        public Source <TOut2, TMat3> ViaMaterialized <TOut2, TMat2, TMat3>(IGraph <FlowShape <TOut, TOut2>, TMat2> flow, Func <TMat, TMat2, TMat3> combine)
        {
            if (flow.Module == GraphStages.Identity <TOut2>().Module)
            {
                if (Keep.IsLeft(combine))
                {
                    return(this as Source <TOut2, TMat3>);
                }

                if (Keep.IsRight(combine))
                {
                    return(MapMaterializedValue(_ => NotUsed.Instance) as Source <TOut2, TMat3>);
                }

                return(MapMaterializedValue(value => combine(value, (TMat2)(object)NotUsed.Instance)) as Source <TOut2, TMat3>);
            }

            var flowCopy = flow.Module.CarbonCopy();

            return(new Source <TOut2, TMat3>(Module
                                             .Fuse(flowCopy, Shape.Outlet, flowCopy.Shape.Inlets.First(), combine)
                                             .ReplaceShape(new SourceShape <TOut2>((Outlet <TOut2>)flowCopy.Shape.Outlets.First()))));
        }