Esempio n. 1
0
        public IValue ReadPair(IRequestFrom from, IKey key, string url)
        {
            Console.WriteLine("from {0} key {1} url {2}", from, key, url);

            if (from == null)
            {
                Console.WriteLine("ReadPair with {0} {1}", key.Key, _hashtable[key.Key]);

                if (_manager.Trykey(key))
                {
                    if (_hashtable[key.Key] != null)
                    {
                        return((IValue)_hashtable[key.Key]);
                    }

                    Console.WriteLine("not found key");
                    RequestFrom req = new RequestFrom(url, _myserver);
                    Console.WriteLine("new request {0}", req._receptor);
                    // Console.WriteLine("to {0}", _mysuccessorServer);
                    bool b = true;
                    while (b)
                    {
                        try
                        {
                            if (_nextserverUri == null)
                            {
                                return(null);
                            }
                            _mysuccessorServer.ReadPair(req, key, null);
                            b = false;
                        }
                        catch (Exception ex)
                        {
                            if (ex is RemotingException || ex is WebException)
                            {
                                Console.WriteLine("***** PROBLEM ON SERVER SUCCESSOR *****");
                                _manager.RemakeRing(_nextserverUri);
                            }
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }

            else
            {
                if (from._from.Equals(_myserver))
                {
                    return(new ValueClass("DONT EXIST"));
                }

                Console.WriteLine("Read Pair on sucessor server {0} {1}", key.Key, _hashtable[key.Key]);

                if (_hashtable[key.Key] != null)
                {
                    Console.WriteLine("Receptor {0}", from._receptor);
                    IClient c = (IClient)Activator.GetObject(typeof(IClient), from._receptor);
                    Console.WriteLine("object client created");
                    c.Receiver((IValue)_hashtable[key.Key]);
                }
                else
                {
                    bool b = true;
                    while (b)
                    {
                        try
                        {
                            if (_nextserverUri == null)
                            {
                                return(null);
                            }
                            _mysuccessorServer.ReadPair(from, key, null);
                            b = false;
                        }
                        catch (Exception ex)
                        {
                            if (ex is RemotingException || ex is WebException)
                            {
                                Console.WriteLine("***** PROBLEM ON SERVER SUCCESSOR *****");
                                _manager.RemakeRing(_nextserverUri);
                            }
                        }
                    }
                }
            }


            return(null);
        }
Esempio n. 2
0
        public IValue ReadPair(IRequestFrom from, IKey key, string url)
        {
            if (from == null)
            {
                if (_manager.Trykey(key))
                {
                    if (_hashtable[key.Key] != null)
                    {
                        return((IValue)_hashtable[key.Key]);
                    }

                    RequestFrom req = new RequestFrom(url, _myserver);

                    bool b = true;
                    while (b)
                    {
                        try
                        {
                            if (_nextserverUri == null)
                            {
                                return(null);
                            }
                            _mysuccessorServer.ReadPair(req, key, null);
                            b = false;
                        }
                        catch (Exception ex)
                        {
                            if (ex is RemotingException || ex is WebException)
                            {
                                _manager.RemakeRing(_nextserverUri);
                            }
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }

            else
            {
                if (from._from.Equals(_myserver))
                {
                    return(new ValueClass("DONT EXIST"));
                }

                if (_hashtable[key.Key] != null)
                {
                    IClient c = (IClient)Activator.GetObject(typeof(IClient), from._receptor);

                    c.Receiver((IValue)_hashtable[key.Key]);
                }
                else
                {
                    bool b = true;
                    while (b)
                    {
                        try
                        {
                            if (_nextserverUri == null)
                            {
                                return(null);
                            }
                            _mysuccessorServer.ReadPair(from, key, null);
                            b = false;
                        }
                        catch (Exception ex)
                        {
                            if (ex is RemotingException || ex is WebException)
                            {
                                _manager.RemakeRing(_nextserverUri);
                            }
                        }
                    }
                }
            }


            return(null);
        }