private void ProcessMessages() { lock (_lockSocket) { if (_stopRequested) { return; } string message; if (!_actor.TryReceiveFrameString(TimeSpan.FromMilliseconds(10), Encoding.ASCII, out message)) { return; } if (message == TaskSchedulerBusCommands.BroadCast.ToString()) { // another node has let us know they are here var fromHostAddress = _actor.ReceiveFrameString(); var msg = fromHostAddress + " broadcasting"; _log.Debug(() => msg); // send back a welcome message via the Bus publisher var reply = _hostAddress + " received"; _actor.SendMoreFrame(TaskSchedulerBusCommands.Publish.ToString()).SendFrame(reply); } else if (message == TaskSchedulerBusCommands.AddedNode.ToString()) { var addedAddress = _actor.ReceiveFrameString(); _log.Debug(() => $"Added node {addedAddress} to the Bus"); } else if (message == TaskSchedulerBusCommands.RemovedNode.ToString()) { var removedAddress = _actor.ReceiveFrameString(); var uri = new Uri(removedAddress); long temp; _otherProcessorCounts.TryRemove(uri.Port, out temp); _log.Debug(() => $"Removed node {removedAddress} from the Bus; it's processing count was {temp}"); RemoteCountChanged?.Invoke(this, EventArgs.Empty); } else if (message == TaskSchedulerBusCommands.SetCount.ToString()) { var key = int.Parse(_actor.ReceiveFrameString()); var value = long.Parse(_actor.ReceiveFrameString()); if (!_otherProcessorCounts.ContainsKey(key)) { _otherProcessorCounts.TryAdd(key, value); } else { _otherProcessorCounts[key] = value; } RemoteCountChanged?.Invoke(this, EventArgs.Empty); } else { //response to broadcast _log.Debug(() => message); } } }