Esempio n. 1
0
        private bool UnregisterUserFromOtherServers(string username)
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }


            bool status = action.UnregisterUser(username);

            Log.Show(_username, "[UNREGISTER USER] Unregister user from self");
            if (status == false)
            {
                Log.Show(_username, "[UNREGISTER USER] Unregister user at self failed!!");
            }

            callback returnedValueOnUnregister1 = new callback();

            callback.RemoteAsyncDelegate RemoteDelForUnregister1 = new callback.RemoteAsyncDelegate(() => server[0].UnregisterUser(username));
            AsyncCallback RemoteCallbackForUnregister1           = new AsyncCallback(returnedValueOnUnregister1.OurRemoteAsyncCallBack);
            IAsyncResult  RemAr1ForUnregister = RemoteDelForUnregister1.BeginInvoke(RemoteCallbackForUnregister1, null);

            callback.RemoteAsyncDelegate RemoteDelForUnregister2 = new callback.RemoteAsyncDelegate(() => server[1].UnregisterUser(username));
            IAsyncResult RemAr2ForUnregister = RemoteDelForUnregister2.BeginInvoke(RemoteCallbackForUnregister1, null);


            Log.Show(_username, "[UNREGISTER USER] Waiting for one Server to return");
            returnedValueOnUnregister1.waiter.WaitOne();
            //returnedValueOnUnregister1.waiter.Reset();

            if (returnedValueOnUnregister1._status == false)
            {
                Log.Show(_username, "[UNREGISTER USER] One of the servers failed to unregister!!");

                returnedValueOnUnregister1.waiter.WaitOne();
                //returnedValueOnUnregister1.waiter.Reset();

                if (returnedValueOnUnregister1._status == false)
                {
                    Log.Show(_username, "[UNREGISTER USER] Both the servers failed to unregister [WEIRD]");
                    return(false);
                }
                else
                {
                    Log.Show(_username, "[UNREGISTER USER] One server successfully unregistered");
                    return(true);
                }
            }
            else
            {
                Log.Show(_username, "[UNREGISTER USER] One server successfully unregistered");
                return(true);
            }
        }
Esempio n. 2
0
        private bool RegisterInfoOnAllServer(ClientMetadata client)
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            callback returnedValueOnRegister1 = new callback();

            callback.RemoteAsyncDelegate RemoteDelforRegister1 = new callback.RemoteAsyncDelegate(() => server[0].WriteClientMetadata(client));
            AsyncCallback RemoteCallbackOnRegister1            = new AsyncCallback(returnedValueOnRegister1.OurRemoteAsyncCallBack);
            IAsyncResult  RemArForRegister1 = RemoteDelforRegister1.BeginInvoke(RemoteCallbackOnRegister1, null);

            callback.RemoteAsyncDelegate RemoteDelforRegister2 = new callback.RemoteAsyncDelegate(() => server[1].WriteClientMetadata(client));
            IAsyncResult RemArForRegister2 = RemoteDelforRegister2.BeginInvoke(RemoteCallbackOnRegister1, null);

            action.WriteClientMetadata(client); //First Self Register
            Log.Show(_username, "[REGISTER CLIENT] Registered on self!!");
            Log.Show(_username, "[REGISTER CLIENT] Waiting for atleast one Server to return");

            returnedValueOnRegister1.waiter.WaitOne();
            //returnedValueOnRegister1.waiter.Reset();

            if (returnedValueOnRegister1._status == false)
            {
                Log.Show(_username, "[REGISTER CLIENT] One of the Servers failed to register");
                returnedValueOnRegister1.waiter.WaitOne();
                // returnedValueOnRegister1.waiter.Reset();

                if (returnedValueOnRegister1._status == false)
                {
                    Log.Show(_username, "[REGISTER CLIENT] Both the Servers failed to register");
                    return(false);
                }
                else
                {
                    Log.Show(_username, "[REGISTER CLIENT] One Server successfully registered");
                    return(true);
                }
            }
            else
            {
                Log.Show(_username, "[REGISTER CLIENT] One Server successfully registered");
                return(true);
            }
        }
Esempio n. 3
0
        private void WriteSequenceNumberOnOtherServers()
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            //Write  generated sequence number to ourself.
            TRYREWRITE:  bool status = action.WriteSequenceNumber(_sequenceNumber,_username);
            if (status == false)
            {
                Log.Show(_username, "[SEQ NUMBER] Generated sequence number write to ourself failed: " + _sequenceNumber);
                _sequenceNumber++;
                goto TRYREWRITE;
            }

            callback returnedValue1 = new callback();
            try
            {
                callback.RemoteAsyncDelegate RemoteDel1 = new callback.RemoteAsyncDelegate(() => server[0].WriteSequenceNumber(_sequenceNumber, _username));
                AsyncCallback RemoteCallback1 = new AsyncCallback(returnedValue1.OurRemoteAsyncCallBack);
                IAsyncResult RemAr1 = RemoteDel1.BeginInvoke(RemoteCallback1, null);

                callback.RemoteAsyncDelegate RemoteDel2 = new callback.RemoteAsyncDelegate(() => server[1].WriteSequenceNumber(_sequenceNumber, _username));
                IAsyncResult RemAr2 = RemoteDel2.BeginInvoke(RemoteCallback1, null);
            }
            catch (Exception e)
            {
                Log.Show(_username, "EXCEPTION: " + e.Message);
            }

            Log.Show(_username, "WAITING HERE FOR FIRST SERVER");
            returnedValue1.waiter.WaitOne();
            //returnedValue1.waiter.Reset();

            if (returnedValue1._status == false)
            {
                Log.Show(_username, "[SEQ NUMBER] One of the Servers failed to set the sequence number: " + _sequenceNumber);
                Log.Show(_username, "WAITING HERE FOR SECOND SERVER ASSUMING FIRST RETURNED FALSE");
                returnedValue1.waiter.WaitOne();
                //returnedValue1.waiter.Reset();

                Log.Show(_username, "STATUS" + returnedValue1._status);

                if (returnedValue1._status == false )
                {
                    Log.Show(_username, "[SEQ NUMBER] Both servers failed to set the sequence number: " + _sequenceNumber);
                    _sequenceNumber++;
                     goto TRYREWRITE; // try until you get a sequence number.
                }
                else
                {
                    Log.Show(_username, "[SEQ NUMBER] One server successfully set the sequence number: " + _sequenceNumber);
                }
            }
            else
            {
                Log.Show(_username, "[SEQ NUMBER] One of the servers successfully set the sequence number: " + _sequenceNumber);

            }
        }
Esempio n. 4
0
        private bool UnregisterUserFromOtherServers(string username)
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            bool status = action.UnregisterUser(username);
            Log.Show(_username, "[UNREGISTER USER] Unregister user from self");
            if (status == false)
            {
                Log.Show(_username, "[UNREGISTER USER] Unregister user at self failed!!");
            }

            callback returnedValueOnUnregister1 = new callback();
            callback.RemoteAsyncDelegate RemoteDelForUnregister1 = new callback.RemoteAsyncDelegate(() => server[0].UnregisterUser(username));
            AsyncCallback RemoteCallbackForUnregister1 = new AsyncCallback(returnedValueOnUnregister1.OurRemoteAsyncCallBack);
            IAsyncResult RemAr1ForUnregister = RemoteDelForUnregister1.BeginInvoke(RemoteCallbackForUnregister1, null);

            callback.RemoteAsyncDelegate RemoteDelForUnregister2 = new callback.RemoteAsyncDelegate(() => server[1].UnregisterUser(username));
            IAsyncResult RemAr2ForUnregister = RemoteDelForUnregister2.BeginInvoke(RemoteCallbackForUnregister1, null);

            Log.Show(_username, "[UNREGISTER USER] Waiting for one Server to return");
            returnedValueOnUnregister1.waiter.WaitOne();
            //returnedValueOnUnregister1.waiter.Reset();

            if (returnedValueOnUnregister1._status == false)
            {
                Log.Show(_username, "[UNREGISTER USER] One of the servers failed to unregister!!");

                returnedValueOnUnregister1.waiter.WaitOne();
                //returnedValueOnUnregister1.waiter.Reset();

                if (returnedValueOnUnregister1._status == false)
                {
                    Log.Show(_username, "[UNREGISTER USER] Both the servers failed to unregister [WEIRD]");
                    return false;
                }
                else
                {
                    Log.Show(_username, "[UNREGISTER USER] One server successfully unregistered");
                    return true;

                }
            }
            else
            {
                Log.Show(_username, "[UNREGISTER USER] One server successfully unregistered");
                return true;
            }
        }
Esempio n. 5
0
        private bool RegisterInfoOnAllServer(ClientMetadata client)
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            callback returnedValueOnRegister1 = new callback();
            callback.RemoteAsyncDelegate RemoteDelforRegister1 = new callback.RemoteAsyncDelegate(() => server[0].WriteClientMetadata(client));
            AsyncCallback RemoteCallbackOnRegister1 = new AsyncCallback(returnedValueOnRegister1.OurRemoteAsyncCallBack);
            IAsyncResult RemArForRegister1 = RemoteDelforRegister1.BeginInvoke(RemoteCallbackOnRegister1, null);

            callback.RemoteAsyncDelegate RemoteDelforRegister2 = new callback.RemoteAsyncDelegate(() => server[1].WriteClientMetadata(client));
            IAsyncResult RemArForRegister2 = RemoteDelforRegister2.BeginInvoke(RemoteCallbackOnRegister1, null);

            action.WriteClientMetadata(client); //First Self Register
            Log.Show(_username, "[REGISTER CLIENT] Registered on self!!");
            Log.Show(_username, "[REGISTER CLIENT] Waiting for atleast one Server to return");

            returnedValueOnRegister1.waiter.WaitOne();
            //returnedValueOnRegister1.waiter.Reset();

            if (returnedValueOnRegister1._status == false)
            {
                Log.Show(_username, "[REGISTER CLIENT] One of the Servers failed to register");
                returnedValueOnRegister1.waiter.WaitOne();
               // returnedValueOnRegister1.waiter.Reset();

                if (returnedValueOnRegister1._status == false)
                {
                    Log.Show(_username, "[REGISTER CLIENT] Both the Servers failed to register");
                    return false;
                }
                else
                {
                    Log.Show(_username, "[REGISTER CLIENT] One Server successfully registered");
                    return true;
                }
            }
            else
            {
                Log.Show(_username, "[REGISTER CLIENT] One Server successfully registered");
                return true;
            }
        }
Esempio n. 6
0
        private void WriteSequenceNumberOnOtherServers()
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            //Write  generated sequence number to ourself.
            TRYREWRITE :  bool status = action.WriteSequenceNumber(_sequenceNumber, _username);
            if (status == false)
            {
                Log.Show(_username, "[SEQ NUMBER] Generated sequence number write to ourself failed: " + _sequenceNumber);
                _sequenceNumber++;
                goto TRYREWRITE;
            }

            callback returnedValue1 = new callback();

            try
            {
                callback.RemoteAsyncDelegate RemoteDel1 = new callback.RemoteAsyncDelegate(() => server[0].WriteSequenceNumber(_sequenceNumber, _username));
                AsyncCallback RemoteCallback1           = new AsyncCallback(returnedValue1.OurRemoteAsyncCallBack);
                IAsyncResult  RemAr1 = RemoteDel1.BeginInvoke(RemoteCallback1, null);


                callback.RemoteAsyncDelegate RemoteDel2 = new callback.RemoteAsyncDelegate(() => server[1].WriteSequenceNumber(_sequenceNumber, _username));
                IAsyncResult RemAr2 = RemoteDel2.BeginInvoke(RemoteCallback1, null);
            }
            catch (Exception e)
            {
                Log.Show(_username, "EXCEPTION: " + e.Message);
            }

            Log.Show(_username, "WAITING HERE FOR FIRST SERVER");
            returnedValue1.waiter.WaitOne();
            //returnedValue1.waiter.Reset();


            if (returnedValue1._status == false)
            {
                Log.Show(_username, "[SEQ NUMBER] One of the Servers failed to set the sequence number: " + _sequenceNumber);
                Log.Show(_username, "WAITING HERE FOR SECOND SERVER ASSUMING FIRST RETURNED FALSE");
                returnedValue1.waiter.WaitOne();
                //returnedValue1.waiter.Reset();

                Log.Show(_username, "STATUS" + returnedValue1._status);

                if (returnedValue1._status == false)
                {
                    Log.Show(_username, "[SEQ NUMBER] Both servers failed to set the sequence number: " + _sequenceNumber);
                    _sequenceNumber++;
                    goto TRYREWRITE;  // try until you get a sequence number.
                }
                else
                {
                    Log.Show(_username, "[SEQ NUMBER] One server successfully set the sequence number: " + _sequenceNumber);
                }
            }
            else
            {
                Log.Show(_username, "[SEQ NUMBER] One of the servers successfully set the sequence number: " + _sequenceNumber);
            }
        }