예제 #1
0
        public JoinBlock(GroupingDataflowBlockOptions dataflowBlockOptions)
        {
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }

            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = CompletionHelper.GetNew(dataflowBlockOptions);

            target1 = new JoinTarget <T1> (this, SignalArrivalTarget, compHelper,
                                           () => outgoing.IsCompleted, dataflowBlockOptions,
                                           dataflowBlockOptions.Greedy, TryAdd1);
            target2 = new JoinTarget <T2> (this, SignalArrivalTarget, compHelper,
                                           () => outgoing.IsCompleted, dataflowBlockOptions,
                                           dataflowBlockOptions.Greedy, TryAdd2);
            target3 = new JoinTarget <T3> (this, SignalArrivalTarget, compHelper,
                                           () => outgoing.IsCompleted, dataflowBlockOptions,
                                           dataflowBlockOptions.Greedy, TryAdd3);
            outgoing = new OutgoingQueue <Tuple <T1, T2, T3> > (
                this, compHelper,
                () => target1.Buffer.IsCompleted || target2.Buffer.IsCompleted ||
                target3.Buffer.IsCompleted,
                _ =>
            {
                target1.DecreaseCount();
                target2.DecreaseCount();
                target3.DecreaseCount();
            }, dataflowBlockOptions);
        }
예제 #2
0
        public BatchedJoinBlock(int batchSize,
                                GroupingDataflowBlockOptions dataflowBlockOptions)
        {
            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException(
                          "batchSize", batchSize, "The batchSize must be positive.");
            }
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }
            if (!dataflowBlockOptions.Greedy)
            {
                throw new ArgumentException(
                          "Greedy must be true for this dataflow block.", "dataflowBlockOptions");
            }
            if (dataflowBlockOptions.BoundedCapacity != DataflowBlockOptions.Unbounded)
            {
                throw new ArgumentException(
                          "BoundedCapacity must be Unbounded or -1 for this dataflow block.",
                          "dataflowBlockOptions");
            }

            BatchSize        = batchSize;
            options          = dataflowBlockOptions;
            completionHelper = CompletionHelper.GetNew(options);

            target1 = new JoinTarget <T1> (
                this, SignalTarget, completionHelper, () => outgoing.IsCompleted,
                dataflowBlockOptions, true, TryAdd);
            target2 = new JoinTarget <T2> (
                this, SignalTarget, completionHelper, () => outgoing.IsCompleted,
                dataflowBlockOptions, true, TryAdd);
            target3 = new JoinTarget <T3> (
                this, SignalTarget, completionHelper, () => outgoing.IsCompleted,
                dataflowBlockOptions, true, TryAdd);

            outgoing = new OutgoingQueue <Tuple <IList <T1>, IList <T2>, IList <T3> > > (
                this, completionHelper,
                () => target1.Buffer.IsCompleted || target2.Buffer.IsCompleted ||
                target3.Buffer.IsCompleted,
                _ =>
            {
                target1.DecreaseCount();
                target2.DecreaseCount();
                target3.DecreaseCount();
            }, options);
        }
예제 #3
0
        public BufferBlock(DataflowBlockOptions dataflowBlockOptions)
        {
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }

            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = CompletionHelper.GetNew(dataflowBlockOptions);
            this.messageBox           = new PassingMessageBox <T> (this, messageQueue, compHelper,
                                                                   () => outgoing.IsCompleted, _ => ProcessQueue(), dataflowBlockOptions);
            this.outgoing = new OutgoingQueue <T> (this, compHelper,
                                                   () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                   dataflowBlockOptions);
        }
예제 #4
0
        public BroadcastBlock(Func <T, T> cloningFunction,
                              DataflowBlockOptions dataflowBlockOptions)
        {
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }

            this.cloningFunction      = cloningFunction;
            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = CompletionHelper.GetNew(dataflowBlockOptions);
            this.messageBox           = new PassingMessageBox <T> (this, messageQueue, compHelper,
                                                                   () => outgoing.IsCompleted, _ => BroadcastProcess(), dataflowBlockOptions);
            this.outgoing = new BroadcastOutgoingQueue <T> (this, compHelper,
                                                            () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                            dataflowBlockOptions, cloningFunction != null);
        }
예제 #5
0
        public BatchBlock(int batchSize, GroupingDataflowBlockOptions dataflowBlockOptions)
        {
            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException("batchSize", batchSize,
                                                      "The batchSize must be positive.");
            }
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException("dataflowBlockOptions");
            }
            if (dataflowBlockOptions.BoundedCapacity != -1 &&
                batchSize > dataflowBlockOptions.BoundedCapacity)
            {
                throw new ArgumentOutOfRangeException("batchSize",
                                                      "The batchSize must be smaller than the value of BoundedCapacity.");
            }

            this.batchSize            = batchSize;
            this.dataflowBlockOptions = dataflowBlockOptions;
            this.compHelper           = CompletionHelper.GetNew(dataflowBlockOptions);

            Action <bool> processQueue;
            Func <bool>   canAccept;

            if (dataflowBlockOptions.MaxNumberOfGroups == -1)
            {
                processQueue = newItem => BatchProcess(newItem ? 1 : 0);
                canAccept    = null;
            }
            else
            {
                processQueue = _ => BatchProcess();
                canAccept    = TryAdd;
            }

            this.messageBox = new PassingMessageBox <T> (this, messageQueue, compHelper,
                                                         () => outgoing.IsCompleted, processQueue, dataflowBlockOptions,
                                                         dataflowBlockOptions.Greedy, canAccept);
            this.outgoing = new OutgoingQueue <T[]> (this, compHelper,
                                                     () => messageQueue.IsCompleted, messageBox.DecreaseCount,
                                                     dataflowBlockOptions, batch => batch.Length);
        }