Esempio n. 1
0
            public bool createPadInt(int id, IdTransaction tId)
            {
                if (failed)
                {
                   throw new NetworkException(this.serverURL, "is not responding.");
                }
                checkFreezed();

                //if padInt already exists
                Monitor.Enter(this);
                if (padIntsMap.ContainsKey(id) || createdPadIntsMap.ContainsKey(id))
                {
                   Monitor.Exit(this);
                   return false;
                }
                Monitor.Exit(this);

                //add PadInt to tid transaction seen PadInts
                addTransactionIfNotPresent(tId);
                insertPadintInTransaction(tId, id);

                Monitor.Enter(this);
                pingData.addNewTransaction(tId, id);
                allPingData.addNewTransaction(tId, id);

                //create PadInt object
                ServerPadInt padInt = new ServerPadInt(id);
                createdPadIntsMap.Add(id, padInt);

                pingData.createdPadInt(id, generatePadIntData(padInt));
                allPingData.createdPadInt(id, generatePadIntData(padInt));

                Monitor.Exit(this);
                return true;
            }
Esempio n. 2
0
            private void applyUpdate(UpdateData data)
            {
                pingData = data;
                Console.WriteLine("Ping Seq: " +lastPingId);
                if (data.createdPadIntsMap.Count != 0)
                {
                   foreach (KeyValuePair<int, PadIntData> entry in data.createdPadIntsMap)
                   {
                  if (!createdPadIntsMap.ContainsKey(entry.Key))
                  {
                     ServerPadInt sp = new ServerPadInt(entry.Key);
                     sp.log.setReadData(entry.Value.lRead);
                     sp.log.setWriteData(entry.Value.lWrite);
                     sp.log.setTentativeData(entry.Value.lTentative);
                     sp.log.setTentativeValueData(entry.Value.lTentativeVal);
                     sp.log.setTentativeReadData(entry.Value.lTentativeRead);
                     sp.setValueData(entry.Value.value);

                     createdPadIntsMap.Add(entry.Key, sp);
                  }
                  allPingData.createdPadInt(entry.Key, entry.Value);
                   }
                }

                if (data.removedCreatedPadInts.Count != 0)
                {
                   foreach (int key in data.removedCreatedPadInts)
                   {
                  if (createdPadIntsMap.ContainsKey(key))
                  {
                     createdPadIntsMap.Remove(key);
                  }

                  allPingData.removeCreatedPadInt(key);
                   }

                }

                if (data.commitedPadIntsMap.Count != 0)
                {
                   foreach (KeyValuePair<int, PadIntData> entry in data.commitedPadIntsMap)
                   {
                  ServerPadInt sp;
                  if (padIntsMap.ContainsKey(entry.Key))
                  {
                     sp = padIntsMap[entry.Key];
                  }
                  else
                  {
                     sp = new ServerPadInt(entry.Key);
                  }

                  sp.log.setReadData(entry.Value.lRead);
                  sp.log.setWriteData(entry.Value.lWrite);
                  sp.log.setTentativeData(entry.Value.lTentative);
                  sp.log.setTentativeValueData(entry.Value.lTentativeVal);
                  sp.setValueData(entry.Value.value);

                  if (!padIntsMap.ContainsKey(entry.Key))
                  {
                     padIntsMap.Add(entry.Key, sp);
                  }

                  allPingData.commitedPadIntsMap.Add(entry.Key, entry.Value);
                   }

                   int actualOccupation = padIntsMap.Count;
                   int actualNumberTransactions = tIdPadIntMap.Count;

                   Monitor.Exit(this);
                   new Thread(delegate()
                   {
                  master.updateChargeServer(serverURL, actualOccupation, actualNumberTransactions);
                   }).Start();
                   Monitor.Enter(this);

                }

                if (data.modifiedPadIntsMap.Count != 0)
                {
                   foreach (KeyValuePair<int, PadIntData> entry in data.modifiedPadIntsMap)
                   {
                  padIntsMap[entry.Key].log.setReadData(entry.Value.lRead);
                  padIntsMap[entry.Key].log.setWriteData(entry.Value.lWrite);
                  padIntsMap[entry.Key].log.setTentativeData(entry.Value.lTentative);
                  padIntsMap[entry.Key].log.setTentativeValueData(entry.Value.lTentativeVal);
                  padIntsMap[entry.Key].setValueData(entry.Value.value);

                  allPingData.addModifiedPadInt(entry.Key, entry.Value);
                   }
                }

                if (data.tIdPadIntMap.Count != 0)
                {
                   foreach (KeyValuePair<IdTransaction, ISet<int>> entry in data.tIdPadIntMap)
                   {
                  if (!tIdPadIntMap.ContainsKey(entry.Key))
                  {
                     tIdPadIntMap.Add(entry.Key, new HashSet<int>());
                  }
                  tIdPadIntMap[entry.Key] = entry.Value;

                  foreach (int padInt in entry.Value)
                  {
                     allPingData.addNewTransaction(entry.Key, padInt);
                  }
                   }
                }

                if (data.removedTransactions.Count != 0)
                {
                   foreach (IdTransaction t in data.removedTransactions)
                   {
                  if (tIdPadIntMap.ContainsKey(t))
                  {
                     tIdPadIntMap.Remove(t);
                  }

                  allPingData.removeTransaction(t);
                   }
                }
            }
Esempio n. 3
0
 /* replication interface */
 private PadIntData generatePadIntData(ServerPadInt padInt)
 {
     return new PadIntData(padInt.log.getReadData(),
                       padInt.log.getWriteData(),
                       padInt.log.getTentativeData(),
                       padInt.log.getTentativeReadData(),
                       padInt.log.getTentativeValueData(),
                       padInt.getValueData());
 }