コード例 #1
0
ファイル: Sources.cs プロジェクト: yfer/akka.net
            public Logic(UnfoldResourceSource <TOut, TSource> source, Attributes inheritedAttributes) : base(source.Shape)
            {
                _source = source;
                _inheritedAttributes = inheritedAttributes;
                _decider             = new Lazy <Decider>(() =>
                {
                    var strategy = _inheritedAttributes.GetAttribute <ActorAttributes.SupervisionStrategy>(null);
                    return(strategy != null ? strategy.Decider : Deciders.StoppingDecider);
                });

                SetHandler(source.Out,
                           onPull: () =>
                {
                    var stop = false;
                    while (!stop)
                    {
                        try
                        {
                            var data = source._readData(_blockingStream);
                            if (data.HasValue)
                            {
                                Push(source.Out, data.Value);
                            }
                            else
                            {
                                CloseStage();
                            }

                            break;
                        }
                        catch (Exception ex)
                        {
                            var directive = _decider.Value(ex);
                            switch (directive)
                            {
                            case Directive.Stop:
                                _source._close(_blockingStream);
                                FailStage(ex);
                                stop = true;
                                break;

                            case Directive.Restart:
                                RestartState();
                                break;

                            case Directive.Resume:
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }
                        }
                    }
                },
                           onDownstreamFinish: CloseStage);
            }
コード例 #2
0
ファイル: Sources.cs プロジェクト: xyicheng/akka.net
            public Logic(UnfoldResourceSource <TOut, TSource> stage, Attributes inheritedAttributes) : base(stage.Shape)
            {
                _stage   = stage;
                _decider = new Lazy <Decider>(() =>
                {
                    var strategy = inheritedAttributes.GetAttribute <ActorAttributes.SupervisionStrategy>(null);
                    return(strategy != null ? strategy.Decider : Deciders.StoppingDecider);
                });

                SetHandler(stage.Out, this);
            }