public void PutMessage(MessageLevel messageLevel, ushort receiverNodeId, ushort receiverWorkerId, ushort senderNodeId, ushort senderWorkerId, int messageType, object content) { //see if it is a local worker that is the receiver lock (_localWorkers) { //Message msg = new Message(messageLevel, new WorkerAddress(receiverNodeId, receiverWorkerId), new WorkerAddress(senderNodeId, senderWorkerId), messageType, content); if (WorkerAddress.IsBroadcastAddress(receiverNodeId, receiverWorkerId)) //broadcast address { foreach (var worker in _localWorkers.Values) { worker.PutMessage(messageLevel, receiverNodeId, receiverWorkerId, senderNodeId, senderWorkerId, messageType, CloneContent(content)); //clone the message to prevent shared state } } else if (_localWorkers.ContainsKey(receiverWorkerId)) { _localWorkers[receiverWorkerId].PutMessage(messageLevel, receiverNodeId, receiverWorkerId, senderNodeId, senderWorkerId, messageType, CloneContent(content)); } else if (!SystemMessages.IsSystemMessageType(messageType)) //we don't care about that { Log.Error("Node.PutMessage : Cannot dispatch message"); } } }
/// <summary> /// Sends a message. /// </summary> /// <param name="receiverAddress">Address of the receicer.</param> /// <param name="messageType">Type of message - user specific.</param> /// <param name="content">The contents of the message.</param> public void Send(WorkerAddress receiverAddress, int messageType, object content) { if (SystemMessages.IsSystemMessageType(messageType)) { Log.Error("Message types smaller than 0 are reserved for system messages. Message type : {0}", messageType); return; } Message msg = new Message(MessageLevel.User, receiverAddress, new WorkerAddress(_node.GetId(), _id), messageType, content); _node.QueueMessage(msg); }