示例#1
0
        /// <summary>
        /// Aborts a transaction on this server
        /// </summary>
        /// <param name="tid">transaction identifier</param>
        /// <param name="usedPadInts">Identifiers of PadInts involved</param>
        /// <returns>A predicate confirming the sucess of the operations</returns>
        internal override bool Abort(int tid, List <int> usedPadInts)
        {
            Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "abort", "tid", tid.ToString() });

            bool resultAbort = true;

            try {
                VerifyPadInts(usedPadInts);

                foreach (int padIntUid in usedPadInts)
                {
                    PadInt padInt = GetPadInt(padIntUid);
                    resultAbort = padInt.Abort(tid) && resultAbort;
                }
            } catch (PadIntNotFoundException) {
                throw;
            }

            /* updates the backup server */
            backupReplyTimer.Start();
            BackupServer.Abort(tid, usedPadInts);
            backupReplyTimer.Stop();

            return(resultAbort);
        }
示例#2
0
        /// <summary>
        /// Writes a value in a PadInt
        /// </summary>
        /// <param name="tid">Transaction identifier</param>
        /// <param name="uid">PadInt identifier</param>
        /// <param name="value">Value of the write</param>
        /// <returns>True if successful</returns>
        internal override bool WritePadInt(int tid, int uid, int value)
        {
            Logger.Log(new String[] { "Server ", Server.ID.ToString(), " writePadInt ", "tid", tid.ToString(), "uid", uid.ToString(), "value", value.ToString() });

            try {
                /* Obtain the PadInt identified by uid */
                PadInt padInt = GetPadInt(uid);

                while (true)
                {
                    if (padInt.GetWriteLock(tid))
                    {
                        padInt.ActualValue = value;
                        /* updates the backup server */
                        backupReplyTimer.Start();
                        BackupServer.WritePadInt(tid, uid, value);
                        backupReplyTimer.Stop();
                        return(true);
                    }
                }
            } catch (PadIntNotFoundException) {
                throw;
            } catch (AbortException) {
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Returns the value of the PadInt when the transaction has the read/write lock.
        ///  Throws an exception if PadInt not found.
        /// </summary>
        /// <param name="tid">Transaction identifier</param>
        /// <param name="uid">PadInt identifier</param>
        /// <returns></returns>
        internal override int ReadPadInt(int tid, int uid)
        {
            Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "readPadInt ", "tid", tid.ToString(), "uid", uid.ToString() });

            try {
                /* Obtain the PadInt identified by uid */
                PadInt padInt = GetPadInt(uid);

                while (true)
                {
                    if (padInt.HasWriteLock(tid) || padInt.GetReadLock(tid))
                    {
                        /* updates the backup server */
                        backupReplyTimer.Start();
                        BackupServer.ReadPadInt(tid, uid);
                        backupReplyTimer.Stop();
                        return(padInt.ActualValue);
                    }
                }
            } catch (PadIntNotFoundException) {
                throw;
            } catch (AbortException) {
                throw;
            }
        }
示例#4
0
        /// <summary>
        /// Sends I'm alive to backup server
        /// </summary>
        internal override void ImAlive()
        {
            Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "ImAlive" });

            imAliveTimer.Stop();
            BackupServer.ImAlive();
            //re-starts the timer
            imAliveTimer.Start();
        }
示例#5
0
        /// <summary>
        /// Deals with backup reply timer events
        /// </summary>
        private void BackupReplyEvent(object source, ElapsedEventArgs e)
        {
            Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "BackupReplyEvent" });
            backupReplyTimer.Stop();
            backupReplyTimer.Close();
            imAliveTimer.Stop();
            imAliveTimer.Close();
            IServerMachine backupServerMachine = (IServerMachine)Activator.GetObject(typeof(IServerMachine), BackupAddress + "Machine");

            backupServerMachine.RestartServer();
            BackupServer.CreateBackupServer(Server.Address, padIntDictionary, false);
        }
示例#6
0
 /// <summary>
 /// Create a PadInt identified by uid
 /// </summary>
 /// <param name="uid">PadInt identifier</param>
 /// <returns></returns>
 internal override bool CreatePadInt(int uid)
 {
     Logger.Log(new String[] { "PrimaryServer", Server.ID.ToString(), "createPadInt", "uid ", uid.ToString(),
                               "    NPadInts", (padIntDictionary.Count + 1).ToString() });
     try {
         padIntDictionary.Add(uid, new PadInt(uid));
         /* updates the backup server */
         backupReplyTimer.Start();
         BackupServer.CreatePadInt(uid);
         backupReplyTimer.Stop();
         return(true);
     } catch (ArgumentException) {
         throw new PadIntAlreadyExistsException(uid, Server.ID);
     }
 }
示例#7
0
 public override bool Status()
 {
     base.Status();
     BackupServer.Status();
     return(true);
 }