/// <summary> /// Sends changes notifications to the connected profile server. /// </summary> /// <param name="Changes">List of changes to send.</param> /// <returns>true if the function succeeds, false otherwise.</returns> public async Task <bool> SendChangeNotifications(List <NeighbourhoodChange> Changes) { log.Trace("()"); bool res = false; Message message = connectedProfileServerMessageBuilder.CreateNeighbourhoodChangedNotificationRequest(Changes); res = await SendMessageAsync(connectedProfileServer, message); log.Trace("(-):{0}", res); return(res); }
/// <summary> /// Adds neighbors to the profile server. /// </summary> /// <param name="NeighborhoodList">List of all servers in the new neighborhood.</param> /// <returns>true if the function succeeds, false otherwise.</returns> public bool AddNeighborhood(List <ProfileServer> NeighborhoodList) { log.Trace("(NeighborhoodList.Count:{0})", NeighborhoodList.Count); List <NeighbourhoodChange> changes = new List <NeighbourhoodChange>(); bool res = false; lock (neighborsLock) { foreach (ProfileServer ps in NeighborhoodList) { // Do not add your own profile server. if (ps.Name == profileServer.Name) { continue; } // Ignore neighbors that we already have in the list. if (neighbors.ContainsKey(ps.Name)) { log.Debug("Profile server '{0}' already has '{1}' as its neighbor.", profileServer.Name, ps.Name); continue; } ps.Lock(); if (ps.IsInitialized()) { neighbors.Add(ps.Name, ps); log.Debug("Profile server '{0}' added to the neighborhood of server '{1}'.", ps.Name, profileServer.Name); // This neighbor server already runs, so we know its profile // we can inform our profile server about it. NeighbourhoodChange change = new NeighbourhoodChange(); change.AddedNodeInfo = ps.GetNodeInfo(); changes.Add(change); } else { // This neighbor server does not run yet, so we do not have its profile. // We will install an event to be triggered when this server starts. log.Debug("Profile server '{0}' is not initialized yet, installing notification for server '{1}'.", ps.Name, profileServer.Name); ps.InstallInitializationNeighborhoodNotification(profileServer); } ps.Unlock(); } } if ((connectedProfileServer != null) && connectedProfileServerWantsUpdates) { // If our profile server is running already, adding servers to its neighborhood // ends with sending update notification to the profile server. if (changes.Count > 0) { log.Debug("Sending {0} neighborhood changes to profile server '{1}'.", changes.Count, profileServer.Name); Message message = connectedProfileServerMessageBuilder.CreateNeighbourhoodChangedNotificationRequest(changes); res = SendMessageAsync(connectedProfileServer, message).Result; } else { log.Debug("No neighborhood changes to send to profile server '{0}'.", profileServer.Name); res = true; } } else { // Our profile server is not started/connected yet, which means we just modified its neighborhood, // and the information about its neighborhood will be send to it once it sends us GetNeighbourNodesByDistanceLocalRequest. log.Debug("Profile server '{0}' is not connected or not fully initialized yet, can't send changes.", profileServer.Name); res = true; } log.Trace("(-):{0}", res); return(res); }