Esempio n. 1
0
        private void processPong(WRGStatus peerStatus)
        {
            try
            {
                if (this.Active && peerStatus.ACTIVE)
                {
                    throw new Exception("<<<More than one ACTIVE WRGs detected!!! Warm the system administrator immediately.>>>");
                }
                if (this.WrgID.Equals(peerStatus.WRGId))
                {
                    throw new Exception("<<<Detected another WRG with the same WRGId: '" + this.WrgID + "' Please alert the system administrator immediately.>>>");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (!peerStatus.ACTIVE && peerStatus.WRGId.CompareTo(WrgID) > 0)
            {
                stateMachine.Fire(Trigger.ElectedActive);
            }
            else
            {
                if (PingTimer == null)
                {
                    PingTimer = new MyTimer(OnPingExpired, Ping_Duration);
                }
                else
                {
                    PingTimer.restart();
                }
            }
        }
Esempio n. 2
0
        private void OnPongReceived(byte[] pongBuffer)
        {
            pongNotReceived = 0;
            waitForPongTimer.stop();
            string    pong      = Encoding.UTF8.GetString(pongBuffer);
            WRGStatus wrgStatus = JsonConvert.DeserializeObject <WRGStatus>(pong);

            processPong(wrgStatus);
        }
Esempio n. 3
0
        private void OnPingReceived(Socket client)
        {
            // reply with a pong
            WRGStatus myWrgStatus = new WRGStatus(WrgID, Active);
            string    json        = JsonConvert.SerializeObject(myWrgStatus);

            client.Send(Encoding.ASCII.GetBytes(json));
            Console.Write("o");
        }