Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParallelVariableLength{TIn, TOut}"/> class.
        /// </summary>
        /// <param name="pipeline">Pipeline to which this component belongs.</param>
        /// <param name="transform">Function mapping keyed input producers to output producers.</param>
        /// <param name="outputDefaultIfDropped">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to a default value.</param>
        /// <param name="defaultValue">Default value to use when messages are dropped in processing one of the input elements.</param>
        /// <param name="name">Name for this component (defaults to ParallelVariableLength).</param>
        /// <param name="defaultDeliveryPolicy">Pipeline-level default delivery policy to be used by this component (defaults to <see cref="DeliveryPolicy.Unlimited"/> if unspecified).</param>
        public ParallelVariableLength(Pipeline pipeline, Func <int, IProducer <TIn>, IProducer <TOut> > transform, bool outputDefaultIfDropped = false, TOut defaultValue = default, string name = null, DeliveryPolicy defaultDeliveryPolicy = null)
            : base(pipeline, name ?? nameof(ParallelVariableLength <TIn, TOut>), defaultDeliveryPolicy)
        {
            this.parallelTransform = transform;
            this.inConnector       = this.CreateInputConnectorFrom <TIn[]>(pipeline, nameof(this.inConnector));
            this.splitter          = this.CreateReceiver <TIn[]>(this, this.Receive, nameof(this.splitter));
            this.inConnector.PipeTo(this.splitter);
            this.activeBranchesEmitter = this.CreateEmitter <int>(this, nameof(this.activeBranchesEmitter));
            var interpolator = outputDefaultIfDropped ? Reproducible.ExactOrDefault <TOut>(defaultValue) : Reproducible.Exact <TOut>();

            this.join = new Join <int, TOut, TOut[]>(
                this,
                interpolator,
                (count, values) => values,
                0,
                count => Enumerable.Range(0, count));

            this.activeBranchesEmitter.PipeTo(this.join.InPrimary);
            this.outConnector = this.CreateOutputConnectorTo <TOut[]>(pipeline, nameof(this.outConnector));
            this.join.PipeTo(this.outConnector);
        }