示例#1
0
        /// <summary>
        ///     创建一个新的消息事务,并将其加入到当前的事务列表中
        /// </summary>
        /// <param name="sequenceId">本次新事务的唯一编号</param>
        /// <param name="channel">消息通信信道</param>
        /// <returns>返回一个新的消息事务</returns>
        /// <exception cref="ArgumentNullException">通信信道不能为空</exception>
        public ThriftMessageTransaction Create(int sequenceId, IMessageTransportChannel <ThriftMessage> channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException("channel");
            }
            ThriftMessageTransaction transaction = new ThriftMessageTransaction(new Lease(DateTime.MaxValue), channel)
            {
                TransactionManager = this, SequenceId = sequenceId
            };
            TransactionIdentity identity = IdentityHelper.Create((IPEndPoint)channel.LocalEndPoint, sequenceId, false);

            transaction.Identity = identity;
            return(Add(transaction) ? transaction : null);
        }
示例#2
0
        private bool Add(ThriftMessageTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }
            ThriftMessageTransaction temp;

            if (_transactions.TryGetValue(transaction.Identity, out temp))
            {
                _tracing.Error("#Cannot add ThriftMessageTransaction to current T-Manager, because the target identity has been dup. \r\nDetails below:\r\nIdentity: {0}", transaction.SequenceId);
                return(false);
            }
            if (!_transactions.TryAdd(transaction.Identity, transaction))
            {
                _tracing.Error("#Add ThriftMessageTransaction to current T-Manager failed. #SequenceId: " + transaction.SequenceId);
                return(false);
            }
            return(true);
        }