/// <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> /// Receive a message from parent BroadcastSender. /// </summary> /// <param name="cancellationSource">The cancellation token for the data reading operation cancellation</param> /// <returns>The incoming message</returns> public T Receive(CancellationTokenSource cancellationSource = null) { PipelineMessage <T> message; var messageList = new List <PipelineMessage <T> >(); do { message = _topology.ReceiveFromParent(cancellationSource); if (_topology.HasChildren()) { _topology.SendToChildren(message, MessageType.Data); } messageList.Add(message); }while (!message.IsLast); return(PipelineDataConverter.FullMessage(messageList)); }