Exemple #1
0
        /// <summary>
        /// Processes a stream of variable-size array messages by creating a stream for each element in the array,
        /// and performing an action on each of these streams.
        /// </summary>
        /// <typeparam name="TIn">Type of input array element.</typeparam>
        /// <param name="source">Source stream.</param>
        /// <param name="streamAction">Action to apply to the individual element streams.</param>
        /// <param name="deliveryPolicy">An optional delivery policy.</param>
        /// <returns>Stream of output arrays.</returns>
        public static IProducer <TIn[]> Parallel <TIn>(
            this IProducer <TIn[]> source,
            Action <int, IProducer <TIn> > streamAction,
            DeliveryPolicy deliveryPolicy = null)
        {
            var p = new ParallelVariableLength <TIn, TIn>(source.Out.Pipeline, streamAction);

            source.PipeTo(p, deliveryPolicy);
            return(source);
        }
Exemple #2
0
        /// <summary>
        /// Transforms a stream of variable-size array messages by creating a stream for each element in the array,
        /// applying a sub-pipeline to each of these streams, and assembling the results into a corresponding output
        /// array stream.
        /// </summary>
        /// <typeparam name="TIn">Type of input array element.</typeparam>
        /// <typeparam name="TOut">Type of output array element.</typeparam>
        /// <param name="source">Source stream.</param>
        /// <param name="streamTransform">Function mapping from an input element stream to an output element stream.</param>
        /// <param name="joinOrDefault">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 default.</param>
        /// <param name="deliveryPolicy">An optional delivery policy.</param>
        /// <returns>Stream of output arrays.</returns>
        public static IProducer <TOut[]> Parallel <TIn, TOut>(
            this IProducer <TIn[]> source,
            Func <int, IProducer <TIn>, IProducer <TOut> > streamTransform,
            bool joinOrDefault            = false,
            DeliveryPolicy deliveryPolicy = null)
        {
            var p = new ParallelVariableLength <TIn, TOut>(source.Out.Pipeline, streamTransform, joinOrDefault);

            return(PipeTo(source, p, deliveryPolicy));
        }
Exemple #3
0
        /// <summary>
        /// Transforms a stream of variable-size array messages by creating a stream for each element in the array,
        /// applying a sub-pipeline to each of these streams, and assembling the results into a corresponding output
        /// array stream.
        /// </summary>
        /// <typeparam name="TIn">Type of input array element.</typeparam>
        /// <typeparam name="TOut">Type of output array element.</typeparam>
        /// <param name="source">Source stream.</param>
        /// <param name="streamTransform">Function mapping from an input element stream to an output element stream.</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="deliveryPolicy">An optional delivery policy.</param>
        /// <returns>Stream of output arrays.</returns>
        public static IProducer <TOut[]> Parallel <TIn, TOut>(
            this IProducer <TIn[]> source,
            Func <int, IProducer <TIn>, IProducer <TOut> > streamTransform,
            bool outputDefaultIfDropped   = false,
            TOut defaultValue             = default,
            DeliveryPolicy deliveryPolicy = null)
        {
            var p = new ParallelVariableLength <TIn, TOut>(source.Out.Pipeline, streamTransform, outputDefaultIfDropped, defaultValue);

            return(PipeTo(source, p, deliveryPolicy));
        }
Exemple #4
0
        /// <summary>
        /// Transforms a stream of variable-size array messages by creating and applying a sub-pipeline to each element in the input array,
        /// and assembling the results into a corresponding output array stream.
        /// </summary>
        /// <typeparam name="TIn">Type of input messages.</typeparam>
        /// <typeparam name="TOut">Type of output messages.</typeparam>
        /// <param name="source">Source stream.</param>
        /// <param name="transformSelector">Function mapping indexes to output producers.</param>
        /// <param name="joinOrDefault">Whether to do an "...OrDefault" join.</param>
        /// <param name="policy">Delivery policy.</param>
        /// <returns>Stream of key to output mappings.</returns>
        public static IProducer <TOut[]> Parallel <TIn, TOut>(
            this IProducer <TIn[]> source,
            Func <int, IProducer <TIn>, IProducer <TOut> > transformSelector,
            bool joinOrDefault    = false,
            DeliveryPolicy policy = null)
        {
            policy = policy ?? DeliveryPolicy.Immediate;
            var p = new ParallelVariableLength <TIn, TOut>(source.Out.Pipeline, transformSelector, joinOrDefault);

            source.PipeTo(p, policy);
            return(p);
        }
Exemple #5
0
        public void ParallelComponentIssolationTest()
        {
            // verify that Parallel* components don't expose emitters of inner Subpipeline
            using (var p = Pipeline.Create())
            {
                var parallel = new ParallelFixedLength <int, int>(p, 10, (i, prod) => prod, false);
                Assert.AreEqual(p, parallel.Out.Pipeline); // composite components shouldn't expose subpipelines

                var parallelVarLen = new ParallelVariableLength <int, int>(p, (i, prod) => prod, false);
                Assert.AreEqual(p, parallelVarLen.Out.Pipeline); // composite components shouldn't expose subpipelines

                var parallelSparse = new ParallelSparseSelect <Dictionary <int, int>, int, int, int, Dictionary <int, int> >(p, _ => _, (i, prod) => prod, _ => _, false);
                Assert.AreEqual(p, parallelSparse.Out.Pipeline); // composite components shouldn't expose subpipelines
            }
        }