Exemplo n.º 1
0
            public override void OnPull()
            {
                var stop = false;

                while (!stop)
                {
                    try
                    {
                        var data = _stage._readData(_blockingStream);
                        if (data.HasValue)
                        {
                            Push(_stage.Out, data.Value);
                        }
                        else
                        {
                            CloseStage();
                        }

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

                        case Directive.Restart:
                            RestartState();
                            break;

                        case Directive.Resume:
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
            }
Exemplo n.º 2
0
            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);
            }
Exemplo n.º 3
0
 private void RestartState()
 {
     _source._close(_blockingStream);
     _blockingStream = _source._create();
 }