/// <summary> /// Sends the message to the Task represented by the given NodeStruct. /// </summary> /// <param name="message">The message to send</param> /// <param name="node">The NodeStruct representing the Task to send to</param> private void SendToNode(T message, NodeStruct <T> node) { GeneralGroupCommunicationMessage gcm = new GroupCommunicationMessage <T>(_groupName, _operatorName, _selfId, node.Identifier, message); _sender.Send(gcm); }
/// <summary> /// Splits the list of messages up into chunks of the specified size /// and sends each sublist to the child Tasks in the specified order. /// </summary> /// <param name="messages">The list of messages to scatter</param> /// <param name="order">The order to send messages</param> /// <param name="type">The message type</param> public void ScatterToChildren(IList <T> messages, List <string> order, MessageType type) { if (messages == null) { throw new ArgumentNullException("messages"); } if (order == null || order.Count != _children.Count) { throw new ArgumentException("order cannot be null and must have the same number of elements as child tasks"); } List <NodeStruct <T> > nodes = new List <NodeStruct <T> >(); foreach (string taskId in order) { NodeStruct <T> node = FindNode(taskId); if (node == null) { throw new IllegalStateException("Received message from invalid task id: " + taskId); } nodes.Add(node); } int count = (int)Math.Ceiling(((double)messages.Count) / _children.Count); ScatterHelper(messages, nodes, count); }
private OperatorTopology( [Parameter(typeof(GroupCommConfigurationOptions.OperatorName))] string operatorName, [Parameter(typeof(GroupCommConfigurationOptions.CommunicationGroupName))] string groupName, [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId, [Parameter(typeof(GroupCommConfigurationOptions.Timeout))] int timeout, [Parameter(typeof(GroupCommConfigurationOptions.RetryCountWaitingForRegistration))] int retryCount, [Parameter(typeof(GroupCommConfigurationOptions.SleepTimeWaitingForRegistration))] int sleepTime, [Parameter(typeof(GroupCommConfigurationOptions.TopologyRootTaskId))] string rootId, [Parameter(typeof(GroupCommConfigurationOptions.TopologyChildTaskIds))] ISet <string> childIds, StreamingNetworkService <GeneralGroupCommunicationMessage> networkService, Sender sender) { _operatorName = operatorName; _groupName = groupName; _selfId = taskId; _timeout = timeout; _retryCount = retryCount; _sleepTime = sleepTime; _nameClient = networkService.NamingClient; _sender = sender; _parent = _selfId.Equals(rootId) ? null : new NodeStruct <T>(rootId); foreach (var childId in childIds) { _childNodeContainer.PutNode(new NodeStruct <T>(childId)); } }
/// <summary> /// Sends the list of messages to the Task represented by the given NodeStruct. /// </summary> /// <param name="messages">The list of messages to send</param> /// <param name="node">The NodeStruct representing the Task to send to</param> private void SendToNode(IList <T> messages, NodeStruct <T> node) { T[] encodedMessages = messages.ToArray(); GroupCommunicationMessage <T> gcm = new GroupCommunicationMessage <T>(_groupName, _operatorName, _selfId, node.Identifier, encodedMessages); _sender.Send(gcm); }
private OperatorTopology( [Parameter(typeof(GroupCommConfigurationOptions.OperatorName))] string operatorName, [Parameter(typeof(GroupCommConfigurationOptions.CommunicationGroupName))] string groupName, [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId, [Parameter(typeof(GroupCommConfigurationOptions.DriverId))] string driverId, [Parameter(typeof(GroupCommConfigurationOptions.Timeout))] int timeout, [Parameter(typeof(GroupCommConfigurationOptions.RetryCount))] int retryCount, [Parameter(typeof(GroupCommConfigurationOptions.TopologyRootTaskId))] string rootId, [Parameter(typeof(GroupCommConfigurationOptions.TopologyChildTaskIds))] ISet <string> childIds, WritableNetworkService <GeneralGroupCommunicationMessage> networkService, Sender sender, IStreamingCodec <T> codec) { _operatorName = operatorName; _groupName = groupName; _selfId = taskId; _driverId = driverId; _timeout = timeout; _retryCount = retryCount; _nameClient = networkService.NamingClient; _sender = sender; _nodesWithData = new BlockingCollection <NodeStruct <T> >(); _children = new List <NodeStruct <T> >(); _idToNodeMap = new Dictionary <string, NodeStruct <T> >(); _codec = codec; if (_selfId.Equals(rootId)) { _parent = null; } else { _parent = new NodeStruct <T>(rootId); _idToNodeMap[rootId] = _parent; } foreach (var childId in childIds) { var node = new NodeStruct <T>(childId); _children.Add(node); _idToNodeMap[childId] = node; } }
private OperatorTopology( [Parameter(typeof(GroupCommConfigurationOptions.OperatorName))] string operatorName, [Parameter(typeof(GroupCommConfigurationOptions.CommunicationGroupName))] string groupName, [Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId, [Parameter(typeof(GroupCommConfigurationOptions.Timeout))] int timeout, [Parameter(typeof(GroupCommConfigurationOptions.RetryCountWaitingForRegistration))] int retryCount, [Parameter(typeof(GroupCommConfigurationOptions.SleepTimeWaitingForRegistration))] int sleepTime, [Parameter(typeof(GroupCommConfigurationOptions.TopologyRootTaskId))] string rootId, [Parameter(typeof(GroupCommConfigurationOptions.TopologyChildTaskIds))] ISet <string> childIds, GroupCommNetworkObserver networkObserver, StreamingNetworkService <GeneralGroupCommunicationMessage> networkService, Sender sender) { _operatorName = operatorName; _groupName = groupName; _selfId = taskId; _timeout = timeout; _retryCount = retryCount; _sleepTime = sleepTime; _nameClient = networkService.NamingClient; _sender = sender; _parent = _selfId.Equals(rootId) ? null : new NodeStruct <T>(rootId, groupName, operatorName); // Register the observers for Task IDs and nodes adjacent to the current node // in the group communication graph. if (_parent != null) { networkObserver.RegisterAndGetForTask(_parent.Identifier).RegisterNodeObserver(new NodeMessageObserver <T>(_parent)); } foreach (var childId in childIds) { var childNode = new NodeStruct <T>(childId, groupName, operatorName); _childNodeContainer.PutNode(childNode); networkObserver.RegisterAndGetForTask(childId).RegisterNodeObserver(new NodeMessageObserver <T>(childNode)); } }
/// <summary> /// Gets the child with the specified identifier. /// </summary> public bool TryGetChild(string identifier, out NodeStruct <T> child) { return(_childIdToNodeMap.TryGetValue(identifier, out child)); }
/// <summary> /// Puts the child node into the container. /// </summary> public void PutNode(NodeStruct <T> childNode) { _childIdToNodeMap.Add(childNode.Identifier, childNode); }
/// <summary> /// Receive a message from the Task represented by the given NodeStruct. /// Removes the NodeStruct from the nodesWithData queue if requested. /// </summary> /// <param name="node">The node to receive from</param> /// <returns>The byte array message from the node</returns> private T[] ReceiveFromNode(NodeStruct <T> node) { var data = node.GetData(); return(data); }
internal NodeMessageObserver(NodeStruct <T> nodeStruct) { _nodeStruct = nodeStruct; }