/// <summary> /// Makes a new cluster, without registrating it - you have to call: <see cref="AddCluster(ItemCluster<T>)"/> to keep it within collection /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public TCluster NewCluster <TCluster>(String name = "") where TCluster : ItemCluster <T>, new() { TCluster output = new TCluster(); output.name = "C" + Clusters.Count(); return(output); }
private Cluster CreateOrUpdateCluster(string component) { if (Clusters.Count(x => x.Label == component) == 0) { Clusters.Add(new Cluster { Label = component, Nodes = new List <Node>() }); } return(Clusters.Where(x => x.Label == component).Single()); }
private void UpdateChartPoints() { for (int i = 0; i < Clusters.Count(); i++) { SeriesCollection.ElementAt(i).Values.Clear(); var values = new ChartValues <ScatterPoint>(); Points.Where(p => p.Cluster.ClusterID == i).ToList().ForEach((point) => { values.Add(new ScatterPoint(point.AttrX, point.AttrY, 1)); }); SeriesCollection.ElementAt(i).Values.AddRange(values); } }
private void ClusterMulticastClientReceive(IAsyncResult ar) { byte[] received = null; try { // Closing? if (clusterMulticastClient == null) { return; } // Receive message try { received = clusterMulticastClient.EndReceive(ar, ref clusterMulticastClientEndPoint); // if (log != null && log.IsDebugEnabled) log.Info("Multicast received from " + clusterMulticastClientEndPoint.Address.ToString() + ": " + received.GetString()); } catch (NullReferenceException) { } catch (ObjectDisposedException) { return; } catch (Exception ex) { if (log != null && log.IsErrorEnabled) { log.Error("ClusterMulticastClientReceive() fail", ex); } } // This may fall thru here if disposing or quitting if (disposed) { return; } // Empty? Quit. if (received == null) { return; } try { // Ignoring message? if (!clientConfig.MulticastEnabled) { return; } // Process received message // Message looks like the following: // HTTP/1.0 200 OK // Date: Wed, 30 Apr 2014 15:23:38 GMT // Sequence: 77 // Digest: 29da46a8d26397116bcb0a8d06e73a89 // Server: c70d84cb-5f51-8544-885d-b2a1451b9aba // X-Manager-Address: 127.0.0.1:6666 // X-Manager-Url: /c70d84cb-5f51-8544-885d-b2a1451b9aba // X-Manager-Protocol: http // X-Manager-Host: myservername string httpCode = received.GetString().Split('\n')[0]; if (!(httpCode.StartsWith("HTTP/1.0 200 OK") || httpCode.StartsWith("HTTP/1.1 200 OK"))) { Dictionary <string, string> goneDataDict = received.ToDictionary(); Cluster goodByeCluster = Clusters.Where(c => c.MulticastServerId == goneDataDict["Server"]).FirstOrDefault(); if (goodByeCluster != null) { if (log.IsDebugEnabled) { log.Debug("ClusterMulticastClient caught server " + goodByeCluster.ClusterUri + " (" + goneDataDict["Server"] + ") is going away"); } goodByeCluster.RouteRegistered = false; } else { if (log.IsDebugEnabled) { log.Debug("ClusterMulticastClient caught server " + goneDataDict["Server"] + " is going away"); } } return; } Dictionary <string, string> dataDict = received.ToDictionary(); Uri clusterUri = null; try { clusterUri = dataDict.GetUriFromBroadcast(); } catch (Exception ex) { if (log.IsDebugEnabled) { log.Debug("ClusterMulticastClient got data that created an invalid uri. Cannot autoregister.", ex); } return; } // Scan to see if we need to add it if (Clusters.Count(c => c.ClusterUri.ToString() == clusterUri.ToString()) > 0) { return; } if (log != null && log.IsInfoEnabled) { log.Info("Multicast received, registering to " + clusterUri); } lock (_globalLockObject) { // Do not start on cluster if no contexts are registered if (clientConfig.RegisteredContexts.Count() + clientConfig.RegisteredContextsFromConfig.Count() == 0) { if (log.IsDebugEnabled) { log.Debug("ClusterMulticastClient did not auto-register cluster " + clusterUri + " because there are no contexts to register, will try again on next multicast receive"); } return; } // Initialize New Cluster try { Cluster cluster = new Cluster(clientConfig) { ClusterUri = clusterUri, MulticastServerId = dataDict["Server"] }; cluster.RegisterRoute(clientConfig.RegisteredContexts.Union(clientConfig.RegisteredContextsFromConfig).Distinct()); Clusters.Add(cluster); } catch (Exception ex) { log.Error("ClusterMulticastClient could not auto-register cluster " + clusterUri + ", will try again on next multicast receive", ex); return; } } } finally { // Listen for the next message clusterMulticastClient.BeginReceive(new AsyncCallback(ClusterMulticastClientReceive), null); } } catch (Exception ex) { if (log != null && log.IsErrorEnabled) { log.Error("ClusterMulticastClientReceive() unhandled exception", ex); } } }