Exemplo n.º 1
0
        /// <summary>
        /// Reads the value of remote PadInt
        /// </summary>
        /// <returns>The value of the remote PadInt</returns>
        public int Read()
        {
            Logger.Log(new String[] { "PadIntStub", "read" });

            try {
                int result;
                if (cache.HasWritePadInt(serverID, uid) || cache.HasReadPadInt(serverID, uid))
                {
                    result = cache.GetPadIntValue(serverID, uid);
                    cache.UpdatePadIntValue(serverID, uid, result);
                }
                else
                {
                    IServer server = (IServer)Activator.GetObject(typeof(IServer), address);
                    result = server.ReadPadInt(tid, uid);
                }
                cache.setPadIntAsRead(serverID, uid);
                return(result);
            } catch (PadIntNotFoundException) {
                try {
                    cache.UpdatePadIntServer(serverID, uid);
                    return(Read());
                } catch (PadIntNotFoundException) {
                    throw;
                }
            } catch (WrongPadIntRequestException) {
                throw;
            } catch (AbortException) {
                Console.WriteLine("Abort Exception: cannot obtain the read lock.");
                PadiDstm.TxAbort();
                throw;
            } catch (SocketException) {
                try {
                    cache.UpdatePadIntServer(serverID, uid);
                    return(Read());
                } catch (PadIntNotFoundException) {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the value on remote PadInt
        /// </summary>
        /// <param name="value">The value to write</param>
        /// <returns>A predicate confirming the sucess of the operations</returns>
        public bool Write(int value)
        {
            Logger.Log(new String[] { "PadIntStub", "write" + "value" + value.ToString() });

            try {
                if (!cache.HasWritePadInt(serverID, uid))
                {
                    IServer server = (IServer)Activator.GetObject(typeof(IServer), address);
                    server.WritePadInt(tid, uid, value);
                    cache.setPadIntAsWrite(serverID, uid);
                }

                cache.UpdatePadIntValue(serverID, uid, value);
                return(true);
            } catch (PadIntNotFoundException) {
                try {
                    cache.UpdatePadIntServer(serverID, uid);
                    return(Write(value));
                } catch (PadIntNotFoundException) {
                    throw;
                }
            } catch (WrongPadIntRequestException) {
                throw;
            } catch (AbortException) {
                Console.WriteLine("Abort Exception: cannot obtain the write lock.");
                PadiDstm.TxAbort();
                throw;
            } catch (SocketException) {
                try {
                    cache.UpdatePadIntServer(serverID, uid);
                    return(Write(value));
                } catch (PadIntNotFoundException) {
                    throw;
                }
            }
        }