Beispiel #1
0
        public void UpdateInfo()
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            callback returnedValueOnUpdate = new callback();

            callback.RemoteUpdateDelegate RemoteDelforUpdate1 = new callback.RemoteUpdateDelegate(server[0].UpdateInfo);
            AsyncCallback RemoteCallbackOnUpdate = new AsyncCallback(returnedValueOnUpdate.OurRemoteUpdateCallBack);
            IAsyncResult  RemArForLookup1        = RemoteDelforUpdate1.BeginInvoke(RemoteCallbackOnUpdate, null);

            callback.RemoteUpdateDelegate RemoteDelforUpdate2 = new callback.RemoteUpdateDelegate(server[1].UpdateInfo);
            IAsyncResult RemArForLookup2 = RemoteDelforUpdate2.BeginInvoke(RemoteCallbackOnUpdate, null);

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

            action.setinfo(returnedValueOnUpdate.info);

            return;
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }
        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);

            }
        }
        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;
            }
        }
        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;
            }
        }
        private ClientMetadata lookUpOnOtherServers(string username)
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            callback returnedValueOnLookup1 = new callback();
            callback.RemoteLookupDelegate RemoteDelforLookup1 = new callback.RemoteLookupDelegate(() => server[0].ReadClientMetadata(username));
            AsyncCallback RemoteCallbackOnLookup1 = new AsyncCallback(returnedValueOnLookup1.OurLookupAsyncCallBack);
            IAsyncResult RemArForLookup1 = RemoteDelforLookup1.BeginInvoke(RemoteCallbackOnLookup1, null);

            callback.RemoteLookupDelegate RemoteDelforLookup2 = new callback.RemoteLookupDelegate(() => server[1].ReadClientMetadata(username));
            IAsyncResult RemArForLookup2 = RemoteDelforLookup2.BeginInvoke(RemoteCallbackOnLookup1, null);

            bool dataEqual;
            ClientMetadata myData = action.ReadClientMetadata(username);

            Log.Show(_username, "[READ METADATA] Waiting for one server to return");
            returnedValueOnLookup1.waiter.WaitOne();
            //returnedValueOnLookup1.waiter.Reset();

            //Compare the received value
            ClientMetadata DataFromServer1 = returnedValueOnLookup1.data;
            dataEqual = CompareValues(myData, DataFromServer1);

            if (dataEqual)
            {
                Log.Show(_username, "[READ METADATA] First retreived value matches");
                return myData;
            }

            else
            {
                Log.Show(_username, "[READ METADATA] Waiting for second server to return");
                returnedValueOnLookup1.waiter.WaitOne();
                //returnedValueOnLookup1.waiter.Reset();

                Log.Show(_username, "[READ METADATA] Second server returned");

                ClientMetadata DataFromServer2 = returnedValueOnLookup1.data;
                dataEqual = CompareValues(myData, DataFromServer2);
                if (dataEqual)
                {
                    Log.Show(_username, "[READ METADATA] Second retreived value matches");
                    return myData;
                }
                else
                {
                    dataEqual = CompareValues(DataFromServer1, DataFromServer1);
                    if (dataEqual)
                    {
                        Log.Show(_username, "[READ METADATA] I have an outdated value. Other two fetched values match");
                        action.WriteClientMetadata(returnedValueOnLookup1.data);
                        Log.Show(_username, "[READ METADATA] Updated my value to one of the received values");
                        return returnedValueOnLookup1.data;
                    }
                    else
                    {
                        Log.Show(_username, "[READ METADATA]ERROR - ERROR");
                        return null;
                    }
                }

            }
        }
        public void UpdateInfo()
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            callback returnedValueOnUpdate = new callback();
            callback.RemoteUpdateDelegate RemoteDelforUpdate1 = new callback.RemoteUpdateDelegate(server[0].UpdateInfo);
            AsyncCallback RemoteCallbackOnUpdate = new AsyncCallback(returnedValueOnUpdate.OurRemoteUpdateCallBack);
            IAsyncResult RemArForLookup1 = RemoteDelforUpdate1.BeginInvoke(RemoteCallbackOnUpdate, null);

            callback.RemoteUpdateDelegate RemoteDelforUpdate2 = new callback.RemoteUpdateDelegate(server[1].UpdateInfo);
            IAsyncResult RemArForLookup2 = RemoteDelforUpdate2.BeginInvoke(RemoteCallbackOnUpdate, null);

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

            action.setinfo(returnedValueOnUpdate.info);

            return;
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        private ClientMetadata lookUpOnOtherServers(string username)
        {
            IConsistencyService[] server = new IConsistencyService[_servers.Count];
            for (int i = 0; i < _servers.Count; i++)
            {
                server[i] = getOtherServers(_servers[i]);
            }

            callback returnedValueOnLookup1 = new callback();

            callback.RemoteLookupDelegate RemoteDelforLookup1 = new callback.RemoteLookupDelegate(() => server[0].ReadClientMetadata(username));
            AsyncCallback RemoteCallbackOnLookup1             = new AsyncCallback(returnedValueOnLookup1.OurLookupAsyncCallBack);
            IAsyncResult  RemArForLookup1 = RemoteDelforLookup1.BeginInvoke(RemoteCallbackOnLookup1, null);

            callback.RemoteLookupDelegate RemoteDelforLookup2 = new callback.RemoteLookupDelegate(() => server[1].ReadClientMetadata(username));
            IAsyncResult RemArForLookup2 = RemoteDelforLookup2.BeginInvoke(RemoteCallbackOnLookup1, null);

            bool           dataEqual;
            ClientMetadata myData = action.ReadClientMetadata(username);

            Log.Show(_username, "[READ METADATA] Waiting for one server to return");
            returnedValueOnLookup1.waiter.WaitOne();
            //returnedValueOnLookup1.waiter.Reset();

            //Compare the received value
            ClientMetadata DataFromServer1 = returnedValueOnLookup1.data;

            dataEqual = CompareValues(myData, DataFromServer1);


            if (dataEqual)
            {
                Log.Show(_username, "[READ METADATA] First retreived value matches");
                return(myData);
            }

            else
            {
                Log.Show(_username, "[READ METADATA] Waiting for second server to return");
                returnedValueOnLookup1.waiter.WaitOne();
                //returnedValueOnLookup1.waiter.Reset();

                Log.Show(_username, "[READ METADATA] Second server returned");

                ClientMetadata DataFromServer2 = returnedValueOnLookup1.data;
                dataEqual = CompareValues(myData, DataFromServer2);
                if (dataEqual)
                {
                    Log.Show(_username, "[READ METADATA] Second retreived value matches");
                    return(myData);
                }
                else
                {
                    dataEqual = CompareValues(DataFromServer1, DataFromServer1);
                    if (dataEqual)
                    {
                        Log.Show(_username, "[READ METADATA] I have an outdated value. Other two fetched values match");
                        action.WriteClientMetadata(returnedValueOnLookup1.data);
                        Log.Show(_username, "[READ METADATA] Updated my value to one of the received values");
                        return(returnedValueOnLookup1.data);
                    }
                    else
                    {
                        Log.Show(_username, "[READ METADATA]ERROR - ERROR");
                        return(null);
                    }
                }
            }
        }