/// <summary> /// 如果订阅者在连接池中,则放回池中 /// </summary> /// <param name="channel"></param> public void BackPool(Subscriber channel) { if (channel == null) { return; } SubscriberUseInfo result = null; lock (_syncLock) { result = ChannelList.Find(p => p.Connector == channel); } if (result != null) { result.IsUsing = false; } }
/// <summary> /// 从池中获取一个服务通道 /// </summary> /// <param name="serviceUri">服务的基地址</param> /// <returns>服务通道对象(消息订阅者对象)</returns> public Subscriber GetServiceChannel(string serviceUri) { lock (_syncLock) { SubscriberUseInfo result = ChannelList.Find(p => p.ServiceUri == serviceUri && !p.IsUsing); if (result == null) { result = new SubscriberUseInfo(); result.Connector = new Subscriber(serviceUri); ChannelList.Add(result); System.Diagnostics.Debug.WriteLine("ChannelList count:" + ChannelList.Count); } result.ServiceUri = serviceUri; result.ActiveTime = DateTime.Now; result.IsUsing = true; return(result.Connector); } }