/// <summary>
 ///     失败的微讯消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">消息通信信道</param>
 public FailMobiSageMessageTransaction(IMessageTransportChannel <BaseMessage> channel)
     : base(channel)
 {
     Identity = new TransactionIdentity {
         EndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1000)
     };
 }
Example #2
0
 /// <summary>
 ///     消息事务,用于承载网络消息处理的专用事务
 ///     <para>* 使用此构造,将会设置当前的事务永远不超时</para>
 /// </summary>
 /// <param name="channel">消息通讯信道</param>
 protected MessageTransaction(IMessageTransportChannel <T> channel)
 {
     _channel     = channel;
     CreateTime   = DateTime.Now;
     RequestTime  = DateTime.MaxValue;
     ResponseTime = DateTime.MaxValue;
 }
Example #3
0
 /// <summary>
 ///     失败的微讯消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="lease">事务生命租期租约</param>
 /// <param name="channel">消息通信信道</param>
 public FailMobiSageMetadataTransaction(ILease lease, IMessageTransportChannel <MetadataContainer> channel)
     : base(lease, channel)
 {
     Identity = new TransactionIdentity {
         EndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1000)
     };
 }
Example #4
0
 /// <summary>
 ///     失败的消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">消息通信信道</param>
 public FailMetadataTransaction(IMessageTransportChannel <MetadataContainer> channel)
     : base(channel)
 {
     Identity = new ErrorTransactionIdentity {
         EndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 1000)
     };
 }
 /// <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);
 }
 /// <summary>
 ///     �ͻ������Ӵ��������ṩ����صĻ�������
 /// </summary>
 /// <param name="channel">�ͻ�������</param>
 /// <param name="transactionManager">���������</param>
 public ThriftConnectionAgent(IMessageTransportChannel<ThriftMessage> channel, ThriftMessageTransactionManager transactionManager)
 {
     if (channel == null) throw new ArgumentNullException("channel");
     if (!channel.IsConnected) throw new ArgumentException("Cannot wrap this msg channel, because current msg channel has been disconnected!");
     if (transactionManager == null) throw new ArgumentNullException("transactionManager");
     _sequenceId = 0;
     _channel = channel;
     _transactionManager = transactionManager;
     _channel.Disconnected += ChannelDisconnected;
     _channel.ReceivedMessage += ChannelReceivedMessage;
 }
        /// <summary>
        ///     创建一个新的消息事务,并将其加入到当前的事务列表中
        ///     <para>* 事务超时时间被设置为KJFramework.Message节点的配置。</para>
        ///     <para>* 默认为: 30S</para>
        /// </summary>
        /// <param name="identity">事务唯一标示</param>
        /// <param name="channel">消息通信信道</param>
        /// <returns>返回一个新的消息事务</returns>
        /// <exception cref="ArgumentNullException">通信信道不能为空</exception>
        public BusinessMessageTransaction Create(TransactionIdentity identity, IMessageTransportChannel <BaseMessage> channel)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            BusinessMessageTransaction transaction = new BusinessMessageTransaction(new Lease(DateTime.Now.Add(TransactionGlobal.TransactionTimeout)), channel)
            {
                TransactionManager = this, Identity = identity
            };

            return(Add(identity, transaction) ? transaction : null);
        }
        void ChannelReceivedMessage(object sender, LightSingleArgEventArgs <List <BaseMessage> > e)
        {
            IMessageTransportChannel <BaseMessage> msgChannel = (IMessageTransportChannel <BaseMessage>)sender;

            foreach (BaseMessage message in e.Target)
            {
                _tracing.Info("L: {0}\r\nR: {1}\r\n{2}", msgChannel.LocalEndPoint, msgChannel.RemoteEndPoint, message.ToString());
                if (message is CSNGetKeyDataResponseMessage || message is CSNGetDataTableResponseMessage || message is CSNGetPartialConfigResponseMessage)
                {
                    _transactionManager.Active(message.TransactionIdentity, message);
                }
            }
        }
        /// <summary>
        ///     创建一个新的消息事务,并将其加入到当前的事务列表中
        /// </summary>
        /// <param name="identity">事务唯一标示</param>
        /// <param name="channel">消息通信信道</param>
        /// <param name="timeout">事务超时时间</param>
        /// <returns>返回一个新的消息事务</returns>
        /// <exception cref="ArgumentNullException">通信信道不能为空</exception>
        public MetadataMessageTransaction Create(TransactionIdentity identity, IMessageTransportChannel <MetadataContainer> channel, TimeSpan timeout)
        {
            if (channel == null)
            {
                throw new ArgumentNullException(nameof(channel));
            }
            MetadataMessageTransaction transaction = new MetadataMessageTransaction(new Lease(DateTime.Now.Add(timeout)), channel)
            {
                TransactionManager = this, Identity = identity
            };

            return(Add(identity, transaction) ? transaction : null);
        }
Example #10
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);
        }
        //new message arrived.
        void ChannelReceivedMessage(object sender, LightSingleArgEventArgs <System.Collections.Generic.List <ThriftMessage> > e)
        {
            IMessageTransportChannel <ThriftMessage> msgChannel = (IMessageTransportChannel <ThriftMessage>)sender;

            foreach (ThriftMessage message in e.Target)
            {
                if (message == null)
                {
                    continue;
                }
                _tracing.Info("L: {0}\r\nR: {1}\r\n{2}", msgChannel.LocalEndPoint, msgChannel.RemoteEndPoint, message.ToString());
                //rebuilds corresponding TransactionIdentity for current RSP message.
                TransactionIdentity identity = IdentityHelper.Create((IPEndPoint)msgChannel.LocalEndPoint, (int)message.Identity.SequenceId, false);
                _transactionManager.Active(identity, message);
            }
        }
 /// <summary>
 ///     连接代理器,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">消息通信信道</param>
 /// <param name="transactionManager">事务管理器</param>
 /// <exception cref="System.NullReferenceException">参数不能为空</exception>
 public IntellectObjectConnectionAgent(IMessageTransportChannel <BaseMessage> channel, MessageTransactionManager transactionManager)
 {
     if (channel == null)
     {
         throw new ArgumentNullException(nameof(channel));
     }
     if (!channel.IsConnected)
     {
         throw new ArgumentException("Cannot wrap this msg channel, because current msg channel has been disconnected!");
     }
     if (transactionManager == null)
     {
         throw new ArgumentNullException(nameof(transactionManager));
     }
     _channel                  = channel;
     _transactionManager       = transactionManager;
     _channel.Disconnected    += ChannelDisconnected;
     _channel.ReceivedMessage += ChannelReceivedMessage;
 }
 /// <summary>
 ///     客户端连接代理器,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">客户端连接</param>
 /// <param name="transactionManager">事务管理器</param>
 public ThriftConnectionAgent(IMessageTransportChannel <ThriftMessage> channel, ThriftMessageTransactionManager transactionManager)
 {
     if (channel == null)
     {
         throw new ArgumentNullException("channel");
     }
     if (!channel.IsConnected)
     {
         throw new ArgumentException("Cannot wrap this msg channel, because current msg channel has been disconnected!");
     }
     if (transactionManager == null)
     {
         throw new ArgumentNullException("transactionManager");
     }
     _sequenceId               = 0;
     _channel                  = channel;
     _transactionManager       = transactionManager;
     _channel.Disconnected    += ChannelDisconnected;
     _channel.ReceivedMessage += ChannelReceivedMessage;
 }
        /// <summary>
        ///     准备与CSN之间的通信连接
        /// </summary>
        /// <exception cref="Exception">准备失败</exception>
        private void PrepareConnection()
        {
            if (_channel != null && _channel.IsConnected)
            {
                return;
            }
            int    offset = _csnAddress.LastIndexOf(':');
            string ip     = _csnAddress.Substring(0, offset);
            int    port   = int.Parse(_csnAddress.Substring(offset + 1, _csnAddress.Length - (offset + 1)));

            IPEndPoint        iep     = new IPEndPoint(IPAddress.Parse(ip), port);
            ITransportChannel channel = new CSNTcpTransportChannel(iep);

            channel.Connect();
            if (!channel.IsConnected)
            {
                throw new Exception("Cannot connect to target CSN service. #address: " + iep);
            }
            _channel = new CSNMessageTransportChannel <BaseMessage>((ICSNRawTransportChannel)channel, _protocolStack);
            _channel.Disconnected    += ChannelDisconnected;
            _channel.ReceivedMessage += ChannelReceivedMessage;
        }
        //new message arrived.
        void ChannelReceivedMessage(object sender, LightSingleArgEventArgs <System.Collections.Generic.List <BaseMessage> > e)
        {
            IMessageTransportChannel <BaseMessage> msgChannel = (IMessageTransportChannel <BaseMessage>)sender;

            foreach (BaseMessage message in e.Target)
            {
                if (message == null)
                {
                    continue;
                }
                _tracing.Info("L: {0}\r\nR: {1}\r\n{2}", msgChannel.LocalEndPoint, msgChannel.RemoteEndPoint, message.ToString());
                TransactionIdentity identity;
                if (message.TransactionIdentity == null)
                {
                    identity = msgChannel.GenerateRequestIdentity(0U);
                }
                else
                {
                    identity = message.TransactionIdentity;
                }
                //response.
                if (!identity.IsRequest)
                {
                    _transactionManager.Active(identity, message);
                    continue;
                }
                //create transaction by IsOneway flag.
                IMessageTransaction <BaseMessage> transaction = new BusinessMessageTransaction(_channel)
                {
                    NeedResponse       = !identity.IsOneway,
                    TransactionManager = _transactionManager,
                    Identity           = identity,
                    Request            = message
                };
                transaction.GetLease().Change(message.ExpireTime);
                NewTransactionHandler(new LightSingleArgEventArgs <IMessageTransaction <BaseMessage> >(transaction));
            }
        }
        //new message arrived.
        void ChannelReceivedMessage(object sender, LightSingleArgEventArgs <List <MetadataContainer> > e)
        {
            IMessageTransportChannel <MetadataContainer> msgChannel = (IMessageTransportChannel <MetadataContainer>)sender;

            foreach (MetadataContainer message in e.Target)
            {
                if (message == null)
                {
                    continue;
                }
                _tracing.Info("L: {0}\r\nR: {1}\r\n{2}", msgChannel.LocalEndPoint, msgChannel.RemoteEndPoint, message.ToString());
                TransactionIdentity identity;
                if (!message.IsAttibuteExsits(0x01))
                {
                    identity = msgChannel.GenerateRequestIdentity(0U);
                }
                else
                {
                    identity = message.GetAttribute(0x01).GetValue <TransactionIdentity>();
                }
                //response.
                if (!identity.IsRequest)
                {
                    _transactionManager.Active(identity, message);
                    continue;
                }
                //create transaction by IsOneway flag.
                IMessageTransaction <MetadataContainer> transaction = new MetadataMessageTransaction(_channel)
                {
                    NeedResponse       = !identity.IsOneway,
                    TransactionManager = _transactionManager,
                    Identity           = identity,
                    Request            = message
                };
                transaction.GetLease().Change(message.GetAttributeAsType <DateTime>(0x02));
                NewTransactionHandler(new LightSingleArgEventArgs <IMessageTransaction <MetadataContainer> >(transaction));
            }
        }
Example #17
0
 /// <summary>
 ///     创建一个新的网络事务
 /// </summary>
 /// <param name="lease">网络事务的生命周期</param>
 /// <param name="channel">网络事务内部包含的通信信道</param>
 /// <returns>返回一个新的网络事务</returns>
 protected override MessageTransaction <MetadataContainer> NewTransaction(Lease lease, IMessageTransportChannel <MetadataContainer> channel)
 {
     return(new MetadataMessageTransaction(lease, channel));
 }
 /// <summary>
 ///     Thrift协议消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="lease">事务生命租期租约</param>
 /// <param name="channel">消息通信信道</param>
 public ThriftMessageTransaction(ILease lease, IMessageTransportChannel<ThriftMessage> channel)
     : base(lease, channel)
 {
     CreateTime = DateTime.Now;
 }
 /// <summary>
 ///     创建一个新的网络事务
 /// </summary>
 /// <param name="lease">网络事务的生命周期</param>
 /// <param name="channel">网络事务内部包含的通信信道</param>
 /// <returns>返回一个新的网络事务</returns>
 protected override MessageTransaction <BaseMessage> NewTransaction(Lease lease, IMessageTransportChannel <BaseMessage> channel)
 {
     return(new BusinessMessageTransaction(lease, channel));
 }
Example #20
0
 /// <summary>
 ///     基础业务消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="lease">事务生命租期租约</param>
 /// <param name="channel">消息通信信道</param>
 public BusinessMessageTransaction(ILease lease, IMessageTransportChannel <BaseMessage> channel)
     : base(lease, channel)
 {
 }
Example #21
0
 /// <summary>
 ///     基础业务消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="channel">消息通信信道</param>
 public BusinessMessageTransaction(IMessageTransportChannel <BaseMessage> channel)
     : base(channel)
 {
 }
 /// <summary>
 ///     创建一个新的网络事务
 /// </summary>
 /// <param name="lease">网络事务的生命周期</param>
 /// <param name="channel">网络事务内部包含的通信信道</param>
 /// <returns>返回一个新的网络事务</returns>
 protected abstract MessageTransaction <TMessage> NewTransaction(Lease lease, IMessageTransportChannel <TMessage> channel);
Example #23
0
 /// <summary>
 ///     基于元数据网络通信协议的消息事务,提供了相关的基本操作
 /// </summary>
 /// <param name="lease">事务生命租期租约</param>
 /// <param name="channel">消息通信信道</param>
 public MetadataMessageTransaction(ILease lease, IMessageTransportChannel <MetadataContainer> channel)
     : base(lease, channel)
 {
 }