Beispiel #1
0
        /// <summary>
        /// Process Command received from the client
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="payload"></param>

        /*public static void DealWithRequestReplicaCommand_thread(CommandReplicas cmd)
         * {
         *  Object tmp;
         *  View v = null;
         *  switch (cmd.GetCommand())
         *  {
         *      case "INVITATION":
         *          v = cmd.GetProposedView();
         *          if (v.GetSequence() <= ServerProgram.GetCurrentViewID().GetSequence())//Reject message if Sequence is less or equal than CurrentView
         *          {
         *              GiveBackResultToReplica(cmd.GetURI(), new CommandReplicas("REFUSE", ServerProgram.GetCurrentViewID(), null, null));
         *          }
         *          else
         *          {
         *              GiveBackResultToReplica(cmd.GetURI(), new CommandReplicas("ACCEPTANCE", ServerProgram.GetCurrentViewID(), ts, ServerProgram.GetMyAddress()));
         *          }
         *          break;
         *      case "ACCEPTANCE":
         *          v = cmd.GetProposedView();
         *          if (v.GetSequence() > ServerProgram.GetCurrentViewID().GetSequence())//Accepts mesaage if Sequence > currentViewID
         *          {
         *              ServerProgram.SetCurrentViewID(v);//Update my view
         *              ts = cmd.GetTSS(); //Update TSS
         *              GiveBackResultToReplica(cmd.GetURI(), new CommandReplicas("COMMIT", ServerProgram.GetCurrentViewID(), ts, ServerProgram.GetMyAddress()));
         *          }
         *          break;
         *      case "COMMIT":
         *          ServerProgram.SetCurrentViewID(v);//Update my view
         *          ts = cmd.GetTSS(); //Update TSS
         *          break;
         *      case "REFUSE":
         *          break;
         *  }
         * }*/


        public void SinkFromReplicas(object cmd) //Receive answers
        {
            CommandReplicas a = cmd as CommandReplicas;

            if (a == null)
            {
                return;
            }

            while (MustFreeze == true)
            {
                ;                            //Freeze
            }
            Thread.Sleep(DelayMessagesTime); //Delay Insertion of messages
            //CommLayer_forReplica.InsertCommand(a);

            /*if (mt != null)
             * {
             *  Console.WriteLine("(ClientServices) RECEBI: " + mt.ToString());
             *
             * }
             * else
             * {
             *  Console.WriteLine("(ClientServices) NADA A RECEBER");
             * }
             * ClientProgram.AnswerIsReceived();*/
        }
Beispiel #2
0
        // ====================================================================================================
        // Services for other Replicas TSS
        // ====================================================================================================
        public void RX_ReplicaCommand(object cmd) //Receive commands from other replicas
        {
            CommandReplicas a = cmd as CommandReplicas;

            if (a == null)
            {
                return;
            }
            Thread.Sleep(DelayMessagesTime);//Delay Insertion of messages
            //CommLayer_forReplica.InsertCommand(a);
        }
Beispiel #3
0
        private static void GiveBackResultToReplica(Uri uri, CommandReplicas cm)
        {
            IServerServices obj = (IServerServices)Activator.GetObject(typeof(IServerServices), uri.AbsoluteUri + "MyRemoteObjectName");

            obj.SinkFromReplicas(cm);
        }
Beispiel #4
0
        /*public void InitFieds(Queue q, List<Command> l)
         * {
         *  CommandQueue = q;
         *  BackLogCommands = l;
         * }*/


        public void InsertCommand(CommandReplicas c)
        {
            CommandQueue.Enqueue(c); //Command in Queue
        }
Beispiel #5
0
        public static void CheckCommandsInQueue_thread_Replica()
        {
            while (true)
            {
                Thread.Sleep(50);                            //Min time to check commands
                if (CommLayer_forReplica.GetQueueSize() > 0) //if there is commands
                {
                    CommandReplicas cmd = CommLayer_forReplica.RemoveFromCommandQueue();
                    //MyTuple payload = (MyTuple)cmd.GetPayload();
                    //Object tmp;

                    switch (cmd.GetCommand())
                    {
                    case "REQUEST_VIEW_AND_IMAGE":      //RECEBI UM PEDIDO
                        Console.WriteLine("-----REQUEST_VIEW_AND_IMAGE-----");

                        //Console.WriteLine("CURRENT VIEW1 ==> " + ServerProgram.GetCurrentViewID().ToString());
                        //Console.WriteLine("CURRENT IMAGE ==> " + ts.ToString());
                        GiveBackResultToReplica(cmd.GetURI(), new CommandReplicas("RECEIVE_VIEW_AND_IMAGE", ServerProgram.GetCurrentViewID(), ts, ServerProgram.GetMyAddress(), ServerProgram.GetMyId()));      //ENVIO O ACK
                        Console.WriteLine("olaaa");
                        ServerProgram.SetStateMachine(ServerProgram.STATE_MACHINE_NETWORK_UPDATE_VIEW);

                        break;

                    case "RECEIVE_VIEW_AND_IMAGE":      //RECEBI UM AKC

                        Console.WriteLine("-----RECEIVE_VIEW_AND_IMAGE----");

                        ServerProgram.SetCurrentViewID(cmd.GetProposedView()); //View update
                        ts = cmd.GetTSS();                                     //tuple space update
                        Console.WriteLine("VIEW RECEBIDA1 ==> " + cmd.GetProposedView().ToString());
                        Console.WriteLine("IMAGEM RECEBIDA1 ==> " + ts.ToString());
                        ServerProgram.wait = false;
                        ServerProgram.SetStateMachine(ServerProgram.STATE_MACHINE_NETWORK_RESTART);

                        break;

                    case "REQUEST_VIEW":
                        Console.WriteLine("-----REQUEST_VIEW-----");           //RECEBI UM PEDIDO

                        //Console.WriteLine("CURRENT VIEW2 ==> " + ServerProgram.GetCurrentViewID().ToString());

                        GiveBackResultToReplica(cmd.GetURI(), new CommandReplicas("RECEIVE_VIEW", ServerProgram.GetCurrentViewID(), null, ServerProgram.GetMyAddress(), ServerProgram.GetMyId()));      //ENVIO O ACK
                        ServerProgram.SetStateMachine(ServerProgram.STATE_MACHINE_NETWORK_WAIT);
                        break;

                    case "RECEIVE_VIEW":        //RECEBI UM AKC

                        Console.WriteLine("-----RECEIVE_VIEW-----");

                        if (cmd.GetURI().AbsolutePath == ServerProgram.RootServer.UID.AbsolutePath)
                        {
                            ServerProgram.root_view = cmd.GetProposedView();
                            //Console.WriteLine("Recebi a view do root ---> " + ServerProgram.root_view.ToString());
                        }
                        ServerProgram.Proposed_Views.Add(cmd.GetProposedView());
                        //Console.WriteLine("VIEW RECEBIDA2 ==> " + cmd.GetProposedView().ToString());
                        ServerProgram.wait = false;
                        ServerProgram.SetStateMachine(ServerProgram.STATE_MACHINE_NETWORK_CHECK_VIEW);
                        break;

                    case "UPDATE_VIEW":         //RECEBI UM PEDIDO DO ROOT PARA FAZER UPDATE DA VIEW
                        Console.WriteLine("-----UPDATE_VIEW-----");

                        ServerProgram.SetCurrentViewID(cmd.GetProposedView());     //View update
                        //Console.WriteLine("NOVA VIEW ==> " + ServerProgram.GetCurrentViewID().ToString());

                        GiveBackResultToReplica(cmd.GetURI(), new CommandReplicas("ACK_UPDATE_VIEW", ServerProgram.GetCurrentViewID(), null, ServerProgram.GetMyAddress(), ServerProgram.GetMyId()));      //ENVIO O ACK
                        ServerProgram.SetStateMachine(ServerProgram.STATE_MACHINE_NETWORK_WAIT);
                        break;

                    case "ACK_UPDATE_VIEW":
                        Console.WriteLine("-----ACK_UPDATE_VIEW-----");           //RECEBI ACK DE CONFIRMAÇÃO DA ALTERAÇÃO DA VIEW
                        ServerProgram.wait = false;
                        ServerProgram.SetStateMachine(ServerProgram.STATE_MACHINE_NETWORK_RESTART);

                        break;
                    }
                }
            }
        }