public void MulticastMsg(ViewMsg msg) { msg.Source = ThisMetaserverId; msg.Status = GetStatus(ThisMetaserverId); ViewElementsMutex.WaitOne( ); //Contact other servers for (int id = 0; id < ViewElements.Length; id++) { if (id == ThisMetaserverId) { continue; } // if ( GetStatus( id ) == ServerStatus.Off ) // continue; msg.Destination = id; log.Debug(DateTime.Now.Ticks + " [M] Multicast View: " + msg.Status); IMetaToMeta server = MetadataServer.ConnectToMetaserver(id); BullyDel invokeDel = new BullyDel(server.BullyRequestsRetrival); AsyncCallback callback = new AsyncCallback(BullyResponse); try { Console.WriteLine("Multicast: " + msg + " to " + msg.Destination); invokeDel.BeginInvoke(msg, callback, null); } catch (SocketException) { UpdateViewServerState(ServerStatus.Off, id, null); } } ViewElementsMutex.ReleaseMutex( ); }
/// <summary> /// Deunnciar que existe um servidor que falhou /// </summary> /// <param name="betrayedServer"></param> /// <param name="knownFrom">Quem o avisou</param> public void ServerBetray(int betrayedServer, int knownFrom) { //Anunciar aos restantes da view que este falhou. ViewMsg msg = new ViewMsg(ViewMsgType.ServerBetray, GetStatus(ThisMetaserverId), ThisMetaserverId, MetadataServer.GetQueueStateVector( )); msg.Source = ThisMetaserverId; msg.Status = GetStatus(ThisMetaserverId); msg.Betrayed = betrayedServer; ViewElementsMutex.WaitOne( ); //Contact other servers for (int id = 0; id < ViewElements.Length; id++) { if (id == ThisMetaserverId || id == knownFrom) { continue; } if (ViewElements[id] == ServerStatus.Off) { Console.WriteLine("Already betrayed" + id); continue; } msg.Destination = id; try { Console.WriteLine("Betray: " + betrayedServer + " to " + msg.Destination); MetadataServer.ConnectToMetaserver(id).BullyRequestsRetrival(msg); } catch (SocketException) { UpdateViewServerState(ServerStatus.Off, id, null); if (id != betrayedServer && !(ViewElements[id].Equals(ServerStatus.Off))) { ServerBetray(id, ThisMetaserverId); } } } //Retirar este servidor da minha view Console.WriteLine("Remove betrayed: " + betrayedServer); RemoveServerFromView(betrayedServer); ViewElementsMutex.ReleaseMutex( ); }
private Boolean UpdateFromServers(List <int> serverIds) { foreach (int serverId in serverIds) { Console.WriteLine("Copy from : " + serverId); IMetaToMeta server = MetadataServer.ConnectToMetaserver(serverId); //Request copy from master try { CopyStructMetadata dataStruct = server.RequestUpdate(MetadataServer.GetQueueStateVector(), MetadataServer.ThisMetaserverId); //Update the server MetadataServer.UpdateServer(dataStruct); } catch (SocketException) { return(false); } } return(true); }