Exemplo n.º 1
0
                public override bool Equals(Object obj)
                {
                    if (obj == null || GetType() != obj.GetType())
                    {
                        return(false);
                    }

                    MyPadInt p = (MyPadInt)obj;

                    return(this.Uid == p.Uid);
                }
Exemplo n.º 2
0
            private void addPadInt(MyPadInt obj)
            {
                int size = padIntsCache.Count;

                if (size == CACHE_SIZE)
                {
                    // remover o PadInt mais antigo
                    Console.WriteLine("Oldest PadInt removed ");
                    padIntsCache.RemoveAt(0);
                }
                padIntsCache.Add(obj);
            }
Exemplo n.º 3
0
 public IPadInt CreatePadInt(int uid)
 {
     try {
         Console.WriteLine("[CREATE] Client wants to create PadInt with id " + uid);
         if (!padInts.Contains(uid))
         {
             if (dataServers.Count == 0)
             {
                 Console.WriteLine("[!CREATE] Error: There are no available DataServers");
                 Console.WriteLine("---");
                 return(null);
             }
             DataServerInfo dServer = (DataServerInfo)dataServers[indexLastServer];
             while (dServer.remoteServer.isFail)
             {
                 Console.WriteLine("[CREATE] DataServer " + dServer.Name /*dServer.remoteServer.name*/ + " is set to [Fail]: Passing his turn on Round Robin");
                 indexLastServer = (indexLastServer + 1) % dataServers.Count; // salta um índice
                 dServer         = (DataServerInfo)dataServers[indexLastServer];
             }
             IPadInt obj = dServer.remoteServer.store(uid);
             // obj nao vem nunca a null porque controlámos isso nos ifs anteriores...
             // Round Robin:
             indexLastServer = (indexLastServer + 1) % dataServers.Count;
             padInts.Add(uid, dServer);
             MyPadInt myPadInt = new MyPadInt(uid, obj);
             addPadInt(myPadInt);
             Console.WriteLine("[CREATE] PadInt " + uid + " stored on " + dServer.Name /*dServer.remoteServer.name*/);
             Console.WriteLine("---");
             return(obj);
         }
         else
         {
             Console.WriteLine("[!CREATE] Error: PadInt " + uid + " already exists.");
             Console.WriteLine("---");
             return(null);
         }
     } catch (RemotingException re) {
         Console.WriteLine("[CreatePadInt]:\n" + re);
         throw new OperationException("CreatePadInt operation at PadInt " + uid + "failed.");
     }
 }
Exemplo n.º 4
0
 // Se o server a que esse objecto pertence estiver em Freeze ou Fail, faz sentido
 // devolvermos o objecto em cache? Não estamos a violar o comportamento suposto?
 //
 // mais: ao devolver o url ao client, nao devemos tambem ir buscar o objecto e por na cache?
 //
 // Se a cache contem o PadInt
 //  retornamos PadInt
 // Caso contrario
 //  retornamos url
 public PadIntInfo AccessPadInt(int uid)
 {
     try {
         Console.WriteLine("[ACCESS] Client requests PadInt with id " + uid);
         if (padIntsCache.Contains(new MyPadInt(uid)))
         {
             int        index      = padIntsCache.IndexOf(new MyPadInt(uid));
             MyPadInt   myObj      = (MyPadInt)padIntsCache[index];
             IPadInt    obj        = myObj.PadInt;
             PadIntInfo padIntInfo = new PadIntInfo(obj);
             Console.WriteLine("[ACCESS] PadInt " + uid + " returned from the cache. ");
             Console.WriteLine("---");
             return(padIntInfo);
         }
         else if (padInts.Contains(uid))
         {
             DataServerInfo dServer    = (DataServerInfo)padInts[uid];
             PadIntInfo     padIntInfo = new PadIntInfo(dServer.URL);
             Console.WriteLine("[ACCESS] Returned " + dServer.Name /*dServer.remoteServer.name*/ + "'s URL, to further access PadInt " + uid + ".");
             Console.WriteLine("---");
             IPadInt  padInt   = dServer.remoteServer.load(uid);
             MyPadInt myPadInt = new MyPadInt(uid, padInt);
             addPadInt(myPadInt);
             return(padIntInfo);
         }
         else     //PadInt nao existe
         {
             Console.WriteLine("[!ACCESS] Error: PadInt " + uid + " does not exist.");
             Console.WriteLine("---");
             return(null);
         }
     } catch (RemotingException re) {
         Console.WriteLine("[AccessPadInt]:\n" + re);
         throw new OperationException("AccessPadInt operation at PadInt " + uid + "failed.");
     }
 }