private void RemoveFromQueue(bool localOnly, string id) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException("The specified entry is not valid", "id"); } ProcessQueue.Remove(x => x.Tag == id); if (!localOnly) { Task.Run(() => { InterNodeCommunicationMessage msg = new InterNodeCommunicationMessage { Tag = id, IsLocalOnly = true, MessageType = InterNodeMessageType.RemoveFromQueue }; // not sure this is valid as its non deterministic lock (KnownNodes) { foreach (var el in KnownNodes) { SendToNode(el, InterNodeCommunicationMessageSerialiser.Serialise(msg)); } } }); } }
private void RemoveFromCache(bool localOnly, string id) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException("The key cannot be null or empty", "id"); } ResultCache.Remove(id, localOnly); if (!localOnly) { Task.Run(() => { InterNodeCommunicationMessage msg = new InterNodeCommunicationMessage { Tag = id, IsLocalOnly = true, MessageType = InterNodeMessageType.RemoveFromCache }; // not sure this is valid as its non deterministic lock (KnownNodes) { foreach (var el in KnownNodes) { SendToNode(el, InterNodeCommunicationMessageSerialiser.Serialise(msg)); } } }); } }
private void internode_OnDataReceived(object sender, SocketDataEventArgs e) { InterNodeCommunicationMessage msg = InterNodeCommunicationMessageSerialiser.Deserialise(e.Data); Console.WriteLine("INCM :: " + msg.MessageType.ToString()); switch (msg.MessageType) { case InterNodeMessageType.AddToCache: // typeof ClientResultMessage AddToCache(msg.IsLocalOnly, msg.Tag, msg.Data); break; case InterNodeMessageType.AddToQueue: // typeof ClientMessage AddToQueue(msg.IsLocalOnly, msg.Data); break; case InterNodeMessageType.RemoveFromCache: RemoveFromCache(msg.IsLocalOnly, msg.Tag); break; case InterNodeMessageType.RemoveFromQueue: RemoveFromQueue(msg.IsLocalOnly, msg.Tag); break; case InterNodeMessageType.NewNodeDiscovered: NewNodeDiscoveredOnNetwork(e.Source); break; case InterNodeMessageType.ChangeMessageStateInQueue: // typeof QueuedProcessState QueueMessageStateChanged(msg.Tag, msg.Data); break; case InterNodeMessageType.FullCacheUpdateSent: SendFullCacheUpdate(e.Source); break; case InterNodeMessageType.FullQueueUpdateSent: SendFullQueueUpdate(e.Source); break; case InterNodeMessageType.FullCacheUpdateReceived: UpdateCacheWithFullUpdate(msg.Data); GetDataFromNode(e.Source, InterNodeMessageType.FullQueueUpdateSent); break; case InterNodeMessageType.FullQueueUpdateReceived: UpdateQueueWithFullUpdate(msg.Data); break; case InterNodeMessageType.StartUp: GetDataFromNode(e.Source, InterNodeMessageType.FullCacheUpdateSent); break; default: Console.WriteLine("Internode message received. Default."); break; } }
private void internode_OnClientConnectCompleted(object sender, IPEndPoint e) { if (e != null) { Console.WriteLine("Client connected..."); InterNodeCommunicationMessage msg = new InterNodeCommunicationMessage { IsLocalOnly = true, MessageType = InterNodeMessageType.StartUp, Tag = e.Address.ToString() }; SendToNode(e.Address, InterNodeCommunicationMessageSerialiser.Serialise(msg)); } }
private void GetDataFromNode(IPAddress ip, InterNodeMessageType msgType) { if (ip == null) { throw new ArgumentException("ip cannot be null"); } if (msgType == InterNodeMessageType.FullQueueUpdateSent || msgType == InterNodeMessageType.FullCacheUpdateSent) { InterNodeCommunicationMessage msg = new InterNodeCommunicationMessage { MessageType = msgType, IsLocalOnly = true }; SendToNode(ip, InterNodeCommunicationMessageSerialiser.Serialise(msg)); } }
private void SendFullQueueUpdate(IPAddress ip) { if (ip == null) { throw new ArgumentException("The specified ip is not valid", "ip"); } IObservableQueue <ClientProcess> temp = ProcessQueue; var msg = new InterNodeCommunicationMessage { Data = PrioritisedQueueSerialiser.Serialise(temp), IsLocalOnly = true, MessageType = InterNodeMessageType.FullQueueUpdateReceived }; SendToNode(ip, InterNodeCommunicationMessageSerialiser.Serialise(msg)); }
private void SendFullCacheUpdate(IPAddress ip) { if (ip == null) { throw new ArgumentException("The specified IP address is not valid", "ip"); } if (!KnownNodes.Contains(ip)) { throw new ArgumentException("The ip address specified is not known.", "ip"); } // grab a copy of the cache CacheProvider <string, ClientResultMessage> temp = ResultCache; temp.ClearSubscribersNoNotify(); InterNodeCommunicationMessage msg = new InterNodeCommunicationMessage { Data = CacheSerialiser.Serialise(temp), IsLocalOnly = true, MessageType = InterNodeMessageType.FullCacheUpdateReceived }; SendToNode(ip, InterNodeCommunicationMessageSerialiser.Serialise(msg)); }