示例#1
0
        public override void Start()
        {
            MetadataServer.PauseServer( );
            long[] state = MetadataServer.GetQueueStateVector( );
            Console.WriteLine("View Pause with state: " + state.ToArray());
            Manager.UpdateViewServerState(ServerStatus.Pause, MetadataServer.ThisMetaserverId, state);

            // ask Paused to other
            Manager.MulticastMsg(new ViewMsg(ViewMsgType.StatusUpdate, ServerStatus.Pause, Manager.ThisMetaserverId, state));
            //Wait to know the state of all new servers
            //Se houver algum online, paused ou ready, queremos saber o estado dele
            //Verificar quais as maiores posicoes
            long[] lastestStatus = WaitUntilSameStatus(state);
            //Deliver all message on application layer
            Console.WriteLine("All message delivered");

            //Change state to ready
            Manager.ToReady();
        }
示例#2
0
 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);
 }
示例#3
0
 public override ViewMsg NewRowdyMsgRequest(int source)
 {
     return(new ViewMsg(ViewMsgType.StatusUpdate, ServerStatus.Off, Manager.ThisMetaserverId, MetadataServer.GetQueueStateVector( )));
 }
示例#4
0
        ///////////////////////////////////////////////// Input //////////////////////////////////////////////
        /// <summary>
        /// Remote Requests: Aqui recebo os pedidos remotos
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public ViewMsg BullyRequestsRetrival(ViewMsg msg)
        {
            switch (msg.Type)
            {
            case ViewMsgType.NewRowdy:
                Console.WriteLine("Retrieve: New Rowdy from: " + msg.Source);
                UpdateViewServerState(ServerStatus.New, msg.Source, null);
                return(ServerViewState.NewRowdyMsgRequest(msg.Source));

            case ViewMsgType.StatusUpdate:
                Console.WriteLine("Retrieve: Status Update from: " + msg.Source + " : " + msg.Status);
                UpdateViewServerState(msg.Status, msg.Source, msg.StateVector);
                ServerViewState.ViewStatusChanged();
                return(new ViewMsg(ViewMsgType.StatusUpdate, GetStatus(ThisMetaserverId), ThisMetaserverId, MetadataServer.GetQueueStateVector( )));

            case ViewMsgType.ServerBetray:
                int betrayed = msg.Betrayed;
                Console.WriteLine("Server betray: " + betrayed);
                if (betrayed == ThisMetaserverId)
                {
                    // Detecta que alguem me está a expulsar e eu estou ligado
                    Console.WriteLine("Server " + msg.Source + " is cheating on me!!!! I will go to new");
                    ToNew(true);
                }
                ServerBetray(msg.Betrayed, msg.Source);
                return(null);

            default:
                Console.WriteLine("Invalide Request type:" + msg.Type + " from " + msg.Source);
                throw new Exception("Invalid Request msg: " + msg.Type);
            }
        }
示例#5
0
        /// <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( );
        }
示例#6
0
        public override void Start()
        {
            Console.WriteLine("View new");
            MetadataServer.PauseServer();
            //Multicast All to STOP. All servers will change to Paused.
            Manager.MulticastMsg(new ViewMsg(ViewMsgType.NewRowdy, ServerStatus.New, Manager.ThisMetaserverId, MetadataServer.GetQueueStateVector( )));

            //ViewStatusChanged will finish and change status:
            //Aguardar que os restantes passem a off ou a paused (ou se for novo, segue
            while (!CheckIfStatusIsKnown())
            {
                lock (locker)
                {
                    Monitor.Wait(locker, 1000);
                }
            }


            CopyProcess( );

            if (Manager.CountOnServers( ) == 1)
            {
                Console.WriteLine("Single server ");
                Manager.ToOnline( );
                return;
            }

            //Change state to ready
            Manager.ToReady();
        }
示例#7
0
 public override ViewMsg NewRowdyMsgRequest(int source)
 {
     //This server is already Ready so just waiting
     return(new ViewMsg(ViewMsgType.StatusUpdate, ServerStatus.Ready, Manager.ThisMetaserverId, MetadataServer.GetQueueStateVector( )));
 }
示例#8
0
        public override void Start()
        {
            Console.WriteLine("View Ready");

            //Multicast I'm ready
            //Multicast All to STOP. All servers will change to Paused.
            Manager.MulticastMsg(new ViewMsg(ViewMsgType.StatusUpdate, ServerStatus.Ready, Manager.ThisMetaserverId, MetadataServer.GetQueueStateVector( )));

            //Wait for all server being ready


            //All servers are paused or off
            // Wait until at least on server is ready
            while (!CheckIfAllServerReady( ))
            {
                lock ( serversReadyLocker )
                {
                    Monitor.Wait(serversReadyLocker, 1000);
                }
                //TODO ao fim de X, voltar atrás e ver se falharam
            }

            //Change to Online
            Manager.ToOnline();
        }
示例#9
0
        public override void Start()
        {
            Console.WriteLine("View online");
            Manager.MulticastMsg(new ViewMsg(ViewMsgType.StatusUpdate, ServerStatus.Online, Manager.ThisMetaserverId, MetadataServer.GetQueueStateVector( )));

            // verificar que todos os estao online ou off agora
            var availableServerStatus = new List <ServerStatus> {
                ServerStatus.Off, ServerStatus.Online
            };

            while (!Manager.CheckServerStatus(availableServerStatus, false))
            {
                Thread.Sleep(100);
            }

            //Restart receiving requests
            MetadataServer.PlayServer();
            Console.WriteLine("Server recovered!! ");
        }