Beispiel #1
0
        /// <summary>
        /// Processes a stream of dictionary messages by creating a stream for each key in the dictionary,
        /// applying a sub-pipeline to each of these streams.
        /// </summary>
        /// <typeparam name="TIn">Type of input dictionary values.</typeparam>
        /// <typeparam name="TKey">Type of input dictionary keys.</typeparam>
        /// <param name="source">Source stream.</param>
        /// <param name="streamAction">The action to apply to each element stream.</param>
        /// <param name="deliveryPolicy">Delivery policy.</param>
        /// <param name="branchTerminationPolicy">Predicate function determining when to terminate branches (defaults to when key no longer present).</param>
        /// <returns>Stream of output dictionaries.</returns>
        public static IProducer <Dictionary <TKey, TIn> > Parallel <TIn, TKey>(
            this IProducer <Dictionary <TKey, TIn> > source,
            Action <TKey, IProducer <TIn> > streamAction,
            DeliveryPolicy deliveryPolicy = null,
            Func <TKey, Dictionary <TKey, TIn>, bool> branchTerminationPolicy = null)
        {
            deliveryPolicy = deliveryPolicy ?? DeliveryPolicy.Immediate;
            var p = new ParallelSparse <TIn, TKey, TIn>(source.Out.Pipeline, streamAction, branchTerminationPolicy);

            source.PipeTo(p, deliveryPolicy);
            return(source);
        }
Beispiel #2
0
        /// <summary>
        /// Create and applies a sub-pipeline to each element in the input collection.
        /// </summary>
        /// <typeparam name="TIn">Type of input messages.</typeparam>
        /// <typeparam name="TKey">Type of key.</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 <Dictionary <TKey, TOut> > Parallel <TIn, TKey, TOut>(
            this IProducer <Dictionary <TKey, TIn> > source,
            Func <TKey, IProducer <TIn>, IProducer <TOut> > transformSelector,
            bool joinOrDefault    = false,
            DeliveryPolicy policy = null)
        {
            policy = policy ?? DeliveryPolicy.Immediate;
            var p = new ParallelSparse <TIn, TKey, TOut>(source.Out.Pipeline, transformSelector, joinOrDefault);

            source.PipeTo(p, policy);
            return(p);
        }
Beispiel #3
0
        /// <summary>
        /// Transforms a stream of dictionary messages by creating a stream for each key in the dictionary,
        /// applying a sub-pipeline to each of these streams, and assembling the results into a corresponding output
        /// dictionary stream.
        /// </summary>
        /// <typeparam name="TIn">Type of input dictionary values.</typeparam>
        /// <typeparam name="TKey">Type of input dictionary keys.</typeparam>
        /// <typeparam name="TOut">Type of output dictionary values.</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">Delivery policy.</param>
        /// <param name="branchTerminationPolicy">Predicate function determining when to terminate sub-pipelines (defaults to when key no longer present).</param>
        /// <returns>Stream of output dictionaries.</returns>
        public static IProducer <Dictionary <TKey, TOut> > Parallel <TIn, TKey, TOut>(
            this IProducer <Dictionary <TKey, TIn> > source,
            Func <TKey, IProducer <TIn>, IProducer <TOut> > streamTransform,
            bool joinOrDefault            = false,
            DeliveryPolicy deliveryPolicy = null,
            Func <TKey, Dictionary <TKey, TIn>, bool> branchTerminationPolicy = null)
        {
            deliveryPolicy = deliveryPolicy ?? DeliveryPolicy.Immediate;
            var p = new ParallelSparse <TIn, TKey, TOut>(source.Out.Pipeline, streamTransform, joinOrDefault, branchTerminationPolicy);

            source.PipeTo(p, deliveryPolicy);
            return(p);
        }
Beispiel #4
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 ParallelSparse <int, int, int>(p, (i, prod) => prod, false);
                Assert.AreEqual(p, parallelSparse.Out.Pipeline); // composite components shouldn't expose subpipelines
            }
        }