当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.getTicket方法代码示例

本文整理汇总了C#中Transaction.getTicket方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.getTicket方法的具体用法?C# Transaction.getTicket怎么用?C# Transaction.getTicket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction.getTicket方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: prepare

        //Participant prepare function invoked by a coordinator.
        public void prepare(Transaction t, string coordinatorURL)
        {
            TransactionInfo tInfo = new TransactionInfo(t);
            _transactions.Add(t.getTicket(), tInfo);

            checkStatus();
            _prevStatus = _status;
            tInfo._coordinatorURL = coordinatorURL;

            bool selfinvolved = false;

            foreach (Request r in t.getRequests())
            {
                PadIntValue value;
                if (_padInts.TryGetValue(r.involved(), out value))
                {
                    selfinvolved = true;

                    if (r.isWrite())
                    {
                        value.setValue(r.getVal());
                        tInfo._valuesToBeChanged.Add(value);
                        Console.WriteLine("Preparing write to padint " + value.getId() + " the value " + value.getValue());
                    }
                    else
                    {
                        Console.WriteLine("Preparing Read of padint " + value.getId() + "it has the value " + value.getValue());
                    }
                }
            }

            if (selfinvolved)
            {
                Console.WriteLine("###############");
                Console.WriteLine("adding uncomm trans Prepare");
                Console.WriteLine("t Request Count: " + t.getRequests().Count());
                Console.WriteLine("t Ticket: " + t.getTicket());
                Console.WriteLine("t TimeStamp: " + t.getTimeStamp());
                Console.WriteLine("###############");
                Console.WriteLine("");
                //add transaction t to the list of uncommited transactions and the ticket to the tickets seen list
                if(!_transactionsUncommited.Contains(t))
                    _transactionsUncommited.Add(t);
            }

            addTicketToList(t.getTicket());
            removeTicketSequence();

            try
            {
                RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
                typeof(RemoteServerInterface), coordinatorURL);
                serv.prepared(t.getTicket(), _ownURL, true);
            }
            catch(TxException e)
            {
                Console.WriteLine("Failed at remote prepare");
                throw e;
            }

            _transactions[t.getTicket()] = tInfo;
        }
开发者ID:JoaoLReis,项目名称:ProjectoAAJ,代码行数:63,代码来源:ServerRemote.cs

示例2: validateLocal

        public void validateLocal(Transaction t)
        {
            TransactionInfo tInfo = _transactions[t.getTicket()];

            RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
            typeof(RemoteServerInterface), tInfo._coordinatorURL);

            tInfo._transactionsUncommited.Clear();
            tInfo._transactionsUncommited.AddRange(_transactionsUncommited);
            //Start the validating proccess
            if (!(t.getTicket() <= _lastTicketTrans))
            {
                tInfo._lastTicketSeen = _lastTicketTrans;
                tInfo._unComTransHandles = new AutoResetEvent[t.getTicket() - tInfo._lastTicketSeen];
                for (int i = 0; i < tInfo._handlerID; i++)
                {
                    tInfo._unComTransHandles[i] = new AutoResetEvent(false);
                }

                if (!WaitHandle.WaitAll(tInfo._unComTransHandles, 2000))
                    serv.validated(t.getTicket(), _ownURL, false);
            }

            // check if the transaction is in conflict with any uncommited transaction before me
            foreach (Transaction tran_last in tInfo._transactionsUncommited)
            {
                if (tran_last.getTicket() < t.getTicket())
                {
                    foreach (Request req_last in tran_last.getRequests())
                        foreach (Request req_act in t.getRequests())
                            if (req_last.involved() == req_act.involved() && req_last.isWrite() == req_act.isWrite())
                                serv.validated(t.getTicket(), _ownURL, false);
                }
            }
            serv.validated(t.getTicket(), _ownURL, true);

            _transactions[t.getTicket()] = tInfo;
        }
开发者ID:JoaoLReis,项目名称:ProjectoAAJ,代码行数:38,代码来源:ServerRemote.cs

示例3: commit

        //Function invoked by a client to commit a transaction.
        public bool commit(Transaction t)
        {
            //Checks the server status.
            checkStatus();

            int ticket = t.getTicket();
            TransactionInfo tInfo = new TransactionInfo(t);

            //Updates current transaction.
            _transactions.Add(t.getTicket(), tInfo);

            //Sets coordinator STATE.
            _prevStatus = _status;

            //Writes to the _valuesToBeChanged list the changes to be executed on this server.
            //Determines who are the participants and stores them on _participants.
            prepExec(ticket);

            List<String> aux = new List<string>();
            aux.AddRange(tInfo._participants);
            aux.Add(_ownURL);

            tInfo = _transactions[ticket];

            broadcast(aux, ticket);

            addTicketToList(t.getTicket());
            removeTicketSequence();

            //Invokes prepare statement on all participants.
            foreach (String p in tInfo._participants)
            {
                try
                {
                    RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
                    typeof(RemoteServerInterface), p);
                    RemoteAsyncPrepare prep = new RemoteAsyncPrepare(serv.prepare);
                    prep.BeginInvoke(t, _ownURL, null, null);
                }
                catch(Exception e)
                {
                    //TODO
                        //Console.WriteLine(e.Message);
                        throw e;
                }
            }

            if (tInfo._participants.Count() > 0)
            {
                if (!WaitHandle.WaitAll(tInfo._handles, 2000))
                    throw new TxException("Receiving Prepares failed");

                resetHandles(t.getTicket());
            }

            tInfo = _transactions[ticket];

            Console.WriteLine("###############");
            Console.WriteLine("Before Validate");
            Console.WriteLine("###############");
            Console.WriteLine("");

            if(validate(ticket))
            {
                foreach (String p in tInfo._participants)
                {
                    try
                    {
                        Console.WriteLine("###############");
                        Console.WriteLine("InsideForeachParticipant");
                        Console.WriteLine("###############");
                        Console.WriteLine("");
                        RemoteServerInterface serv = (RemoteServerInterface)Activator.GetObject(
                        typeof(RemoteServerInterface), p);
                        RemoteAsyncCommitLocalChanges prep = new RemoteAsyncCommitLocalChanges(serv.commitLocalChanges);
                        prep.BeginInvoke(t.getTicket(), null, null);
                    }
                    catch(TxException e)
                    {
                        Console.WriteLine(e.Message);
                        throw e;
                    }
                }

                Console.WriteLine("###############");
                Console.WriteLine("Before HandleReception");
                Console.WriteLine("###############");
                Console.WriteLine("");
                if (tInfo._participants.Count() > 0)
                {
                    if (!WaitHandle.WaitAll(tInfo._handles, 2000))
                        throw new TxException("Receiving Commit failed");
                    resetHandles(t.getTicket());
                }

                tInfo = _transactions[ticket];

                //Commiting local changes
                foreach (PadIntValue item in tInfo._valuesToBeChanged)
//.........这里部分代码省略.........
开发者ID:JoaoLReis,项目名称:ProjectoAAJ,代码行数:101,代码来源:ServerRemote.cs


注:本文中的Transaction.getTicket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。