/// <summary> /// Sends the data to the operator's ReduceReceiver to be aggregated. /// </summary> /// <param name="data">The data to send</param> /// <param name="cancellationSource">The cancellationSource for cancel the operation</param> public void Send(T data, CancellationTokenSource cancellationSource = null) { var messageList = PipelineDataConverter.PipelineMessage(data); if (data == null) { throw new ArgumentNullException("data"); } foreach (var message in messageList) { if (_topology.HasChildren()) { var reducedValueOfChildren = _topology.ReceiveFromChildren(_pipelinedReduceFunc, cancellationSource); var mergeddData = new List <PipelineMessage <T> > { message }; if (reducedValueOfChildren != null) { mergeddData.Add(reducedValueOfChildren); } var reducedValue = _pipelinedReduceFunc.Reduce(mergeddData); _topology.SendToParent(reducedValue, MessageType.Data); } else { _topology.SendToParent(message, MessageType.Data); } } }
/// <summary> /// Receives messages sent by all ReduceSenders and aggregates them /// using the specified IReduceFunction. /// </summary> /// <returns>The single aggregated data</returns> public T Reduce() { PipelineMessage <T> message; var messageList = new List <PipelineMessage <T> >(); do { message = _topology.ReceiveFromChildren(_pipelinedReduceFunc); messageList.Add(message); }while (!message.IsLast); return(PipelineDataConverter.FullMessage(messageList)); }