Example #1
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="shape">TBD</param>
        /// <param name="attributes">TBD</param>
        /// <param name="stage">TBD</param>
        public PushPullGraphLogic(
            FlowShape <TIn, TOut> shape,
            Attributes attributes,
            AbstractStage <TIn, TOut> stage)
            : base(shape)
        {
            Attributes    = attributes;
            _currentStage = Stage = stage;
            _shape        = shape;

            SetHandler(_shape.Inlet, onPush: () =>
            {
                try
                {
                    _currentStage.OnPush(Grab(_shape.Inlet), Context);
                }
                catch (Exception e)
                {
                    OnSupervision(e);
                }
            },
                       onUpstreamFailure: exception => _currentStage.OnUpstreamFailure(exception, Context),
                       onUpstreamFinish: () => _currentStage.OnUpstreamFinish(Context));

            SetHandler(_shape.Outlet,
                       onPull: () => _currentStage.OnPull(Context),
                       onDownstreamFinish: () => _currentStage.OnDownstreamFinish(Context));
        }
Example #2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <exception cref="NotSupportedException">TBD</exception>
        /// <returns>TBD</returns>
        public ITerminationDirective AbsorbTermination()
        {
            if (IsClosed(_shape.Outlet))
            {
                var exception = new NotSupportedException("It is not allowed to call AbsorbTermination() from OnDownstreamFinish.");
                // This MUST be logged here, since the downstream has cancelled, i.e. there is no one to send onError to, the
                // stage is just about to finish so no one will catch it anyway just the interpreter

                Interpreter.Log.Error(exception.Message);
                throw exception;    // We still throw for correctness (although a finish() would also work here)
            }

            if (IsAvailable(_shape.Outlet))
            {
                _currentStage.OnPull(Context);
            }
            return(null);
        }