コード例 #1
0
ファイル: Sources.cs プロジェクト: xyicheng/akka.net
            public override void OnPull()
            {
                var source  = _stage._sourceFactory();
                var subSink = new SubSinkInlet <TOut>(this, "LazySource");

                subSink.Pull();

                SetHandler(_stage.Out, () => subSink.Pull(), () =>
                {
                    subSink.Cancel();
                    CompleteStage();
                });

                subSink.SetHandler(new LambdaInHandler(() => Push(_stage.Out, subSink.Grab())));

                try
                {
                    var value = SubFusingMaterializer.Materialize(source.ToMaterialized(subSink.Sink, Keep.Left),
                                                                  _inheritedAttributes);
                    _completion.SetResult(value);
                }
                catch (Exception e)
                {
                    subSink.Cancel();
                    FailStage(e);
                    _completion.TrySetException(e);
                }
            }
コード例 #2
0
ファイル: RestartFlow.cs プロジェクト: jarlrasm/akka.net
        protected SubSinkInlet <TOut> CreateSubInlet(Outlet <TOut> outlet)
        {
            var sinkIn = new SubSinkInlet <TOut>(this, $"RestartWithBackoff{_name}.subIn");

            sinkIn.SetHandler(new LambdaInHandler(
                                  onPush: () => Push(Out, sinkIn.Grab()),
                                  onUpstreamFinish: () =>
            {
                if (_finishing || MaxRestartsReached() || _onlyOnFailures)
                {
                    Complete(Out);
                }
                else
                {
                    ScheduleRestartTimer();
                }
            },

                                  /*
                                   * upstream in this context is the wrapped stage
                                   */
                                  onUpstreamFailure: ex =>
            {
                if (_finishing || MaxRestartsReached())
                {
                    Fail(Out, ex);
                }
                else
                {
                    Log.Warning(ex, "Restarting graph due to failure.");
                    ScheduleRestartTimer();
                }
            }));

            SetHandler(Out,
                       onPull: () => sinkIn.Pull(),
                       onDownstreamFinish: () =>
            {
                _finishing = true;
                sinkIn.Cancel();
            });

            return(sinkIn);
        }
コード例 #3
0
ファイル: Restart.cs プロジェクト: xyicheng/akka.net
        protected SubSinkInlet <T> CreateSubInlet <T>(Outlet <T> outlet)
        {
            var sinkIn = new SubSinkInlet <T>(this, $"RestartWithBackoff{_name}.subIn");

            sinkIn.SetHandler(new LambdaInHandler(
                                  onPush: () =>
            {
                Push(Out, sinkIn.Grab());
            },
                                  onUpstreamFinish: () =>
            {
                if (_finishing)
                {
                    Complete(Out);
                }
                else
                {
                    Log.Debug("Graph out finished");
                    OnCompleteOrFailure();
                }
            },
                                  onUpstreamFailure: ex =>
            {
                if (_finishing)
                {
                    Fail(_shape.Outlets.First(), ex);
                }
                else
                {
                    Log.Error(ex, "Restarting graph due to failure");
                    OnCompleteOrFailure();
                }
            }));

            SetHandler(Out,
                       onPull: () => sinkIn.Pull(),
                       onDownstreamFinish: () =>
            {
                _finishing = true;
                sinkIn.Cancel();
            });

            return(sinkIn);
        }
コード例 #4
0
 public override void OnPush() => Push(_stage.Outlet, _sinkIn.Grab());