OutboundConnectionHandler(StreamsTransport transport, Address remoteAddress, EndPoint remoteSocketAddr)
        {
            var settings           = transport.Settings;
            var transmissionHandle =
                Source.ActorRef <Google.Protobuf.ByteString>(settings.BufferedMessages, OverflowStrategy.Backpressure);
            var fromLocalActors = FromProtobuf().Via(Encode(4, settings.MaxFrameSize, settings.ByteOrder));


            var fromRemoteActors = Decode(4, settings.MaxFrameSize, settings.ByteOrder).Via(ToProtobuf());

            var transmissionRef = transmissionHandle.PreMaterialize(transport.StreamMaterializer);

            var finalOutput = new RemoteOutboundAssociationSink(transport, remoteAddress, remoteSocketAddr, transmissionRef.Item1);

            var dsl = GraphDsl.Create(finalOutput, (builder, remoteOutput) =>
            {
                // local stages
                var localInput       = builder.Add(transmissionRef.Item2);
                var compilerCeremony = builder.Add(Flow.Create <Google.Protobuf.ByteString>());
                var local            = builder.Add(fromLocalActors);
                var merge            = builder.Add(new Merge <Google.Protobuf.ByteString, Google.Protobuf.ByteString>(2, false));
                builder.From(localInput.Outlet).To(merge.In(0));
                builder.From(compilerCeremony.Outlet).To(merge.In(1));
                builder.From(merge.Out).To(local.Inlet);

                // remote stages
                var remote = builder.Add(fromRemoteActors);
                builder.From(remote.Outlet).To(remoteOutput.Inlet);

                return(new BidiShape <ByteString, Google.Protobuf.ByteString, Google.Protobuf.ByteString, ByteString>(remote.Inlet, remote.Outlet, compilerCeremony.Inlet, local.Outlet));
            });

            return(BidiFlow.FromGraph(dsl));
        }
示例#2
0
        private static BidiFlow <int, long, ByteString, string, Task <int> > BidiMaterialized()
        {
            return(BidiFlow.FromGraph(GraphDsl.Create(Sink.First <int>(), (b, s) =>
            {
                b.From(Source.Single(42).MapMaterializedValue(_ => Task.FromResult(0))).To(s);

                var top = b.Add(Flow.Create <int>().Select(x => ((long)x) + 2));
                var bottom = b.Add(Flow.Create <ByteString>().Select(x => x.ToString(Encoding.UTF8)));
                return new BidiShape <int, long, ByteString, string>(top.Inlet, top.Outlet, bottom.Inlet, bottom.Outlet);
            })));
        }
示例#3
0
        public void ActorGraphInterpreter_should_be_able_to_interpret_a_simple_bidi_stage()
        {
            this.AssertAllStagesStopped(() =>
            {
                var identityBidi = new IdentityBidiGraphStage();
                var identity     = BidiFlow.FromGraph(identityBidi).Join(Flow.Identity <int>().Select(x => x));

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

                task.AwaitResult().Should().Equal(Enumerable.Range(1, 10));
            }, Materializer);
        }
        public void ActorGraphInterpreter_should_be_able_to_interpret_and_reuse_a_simple_bidi_stage()
        {
            this.AssertAllStagesStopped(() =>
            {
                var identityBidi     = new IdentityBidiGraphStage();
                var identityBidiFlow = BidiFlow.FromGraph(identityBidi);
                var identity         = identityBidiFlow.Atop(identityBidiFlow).Atop(identityBidiFlow).Join(Flow.Identity <int>().Select(x => x));

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

                task.Wait(TimeSpan.FromSeconds(3)).Should().BeTrue();
                task.Result.Should().Equal(Enumerable.Range(1, 10));
            }, _materializer);
        }