private void ApplicationServiceConnect(ApportionDispatcher apportionDispatcher) { var appWorkerConnectionDispatcher = apportionDispatcher.CreateApplicationWorkerChannelDispatcher(_dispatchers, ConnectionWorkType.ApplicationServiceConnection); appWorkerConnectionDispatcher.ListByteBuffer.AddRange(apportionDispatcher.GetACKPacketData().BuilderHeadPacket()); if (apportionDispatcher.ListByteBuffer.Count > 0) { var bufferData = apportionDispatcher.ListByteBuffer.ToArray(); appWorkerConnectionDispatcher.ListByteBuffer.AddRange(bufferData); } this._dispatchers.Add(appWorkerConnectionDispatcher.DispatcherId, appWorkerConnectionDispatcher); this._appServiceChannels.Add(new Tuple <long, long>(apportionDispatcher.GetAccessId(), appWorkerConnectionDispatcher.DispatcherId)); this.OnConnectedEventHandler?.Invoke(appWorkerConnectionDispatcher); //找到相应主控端连接 TcpSessionChannelDispatcher dispatcher; if (_dispatchers.TryGetValue(apportionDispatcher.GetAccessId(), out dispatcher)) { var data = MessageHelper.CopyMessageHeadTo(MessageHead.MID_APPWORK); dispatcher.SendTo(data); } else { appWorkerConnectionDispatcher.CloseSession(); this.LogOutputEventHandler?.Invoke(LogOutLevelType.Debug, $"应用服务工作连接未找到相应的主控端!"); } }
private void ApplicationServiceConnect(ApportionDispatcher apportionDispatcher) { //找到相应主控端连接 TcpSessionChannelDispatcher dispatcher; if (_dispatchers.TryGetValue(apportionDispatcher.GetAccessId(), out dispatcher)) { var appWorkerConnectionDispatcher = apportionDispatcher.CreateApplicationWorkerChannelDispatcher(_dispatchers, ConnectionWorkType.ApplicationServiceConnection); this._appServiceChannels.Add(new Tuple <long, long>(apportionDispatcher.GetAccessId(), appWorkerConnectionDispatcher.DispatcherId)); var data = MessageHelper.CopyMessageHeadTo(MessageHead.MID_APPWORK); dispatcher.SendTo(data); } }
public static TcpSessionMainApplicationConnection CreateMainApplicationChannelDispatcher(this ApportionDispatcher apportionDispatcher, IDictionary <long, TcpSessionChannelDispatcher> dispatchers) { var accessId = apportionDispatcher.GetAccessId(); var mainappChannelDispatcher = new TcpSessionMainApplicationConnection(dispatchers); mainappChannelDispatcher.DispatcherId = accessId; mainappChannelDispatcher.SetSession(apportionDispatcher.CurrentSession); var bufferData = apportionDispatcher.ListByteBuffer.ToArray(); if (bufferData.Length > 0)//如缓冲区有数据,则处理消息 { mainappChannelDispatcher.ListByteBuffer.AddRange(bufferData); mainappChannelDispatcher.OnMessage(); } return(mainappChannelDispatcher); }
private void MainApplicationConnect(ApportionDispatcher apportionDispatcher) { var accessId = apportionDispatcher.GetAccessId(); var mainappChannelDispatcher = apportionDispatcher.CreateMainApplicationChannelDispatcher(_dispatchers); if (!_dispatchers.ContainsKey(accessId))//可能重连太快 { //主控端使用自身AccessId作索引 _dispatchers.Add(accessId, mainappChannelDispatcher); } else { var aboutOfCloseDispatcher = _dispatchers[accessId]; var data = MessageHelper.CopyMessageHeadTo(MessageHead.MID_LOGOUT, new LogOutPacket() { Message = "已有相同Id的主控端登陆,你已被登出!" }); aboutOfCloseDispatcher.SendTo(data); aboutOfCloseDispatcher.CloseSession(); } }
private void MainApplicationConnect(ApportionDispatcher apportionDispatcher) { var accessId = apportionDispatcher.GetAccessId(); var mainappChannelDispatcher = apportionDispatcher.CreateMainApplicationChannelDispatcher(_dispatchers); if (_dispatchers.ContainsKey(accessId))//可能重连太快 { var aboutOfCloseDispatcher = _dispatchers[accessId]; var data = MessageHelper.CopyMessageHeadTo(MessageHead.MID_LOGOUT, new LogOutPacket() { Message = "已有相同Id的主控端登陆,你已被登出" }); aboutOfCloseDispatcher.SendTo(data); aboutOfCloseDispatcher.CloseSession();//调用后底层会触发Closed事件 this.LogOutputEventHandler?.Invoke(LogOutLevelType.Debug, $"有相同Id:{accessId}的主控端登陆!"); } _dispatchers.Add(accessId, mainappChannelDispatcher); this.OnConnectedEventHandler?.Invoke(mainappChannelDispatcher); }
private void ApplicationConnect(ApportionDispatcher apportionDispatcher) { TcpSessionChannelDispatcher dispatcher; var serviceWorkerChannelItem = this._appServiceChannels.FirstOrDefault(c => c.Item1 == apportionDispatcher.GetAccessId()); if (!serviceWorkerChannelItem.IsNull() && _dispatchers.TryGetValue(serviceWorkerChannelItem.Item2, out dispatcher)) { var serviceChannelDispatcher = dispatcher.ConvertTo <TcpSessionApplicationWorkerConnection>(); var appChannelDispatcher = apportionDispatcher.CreateApplicationWorkerChannelDispatcher(_dispatchers, ConnectionWorkType.ApplicationConnection); if (!serviceChannelDispatcher.IsJoin) { serviceChannelDispatcher.Join(appChannelDispatcher); serviceChannelDispatcher.OnMessage(); appChannelDispatcher.OnMessage(); } this._appServiceChannels.Remove(serviceWorkerChannelItem); _dispatchers.Add(appChannelDispatcher.DispatcherId, appChannelDispatcher); } }
private void ApplicationConnect(ApportionDispatcher apportionDispatcher) { TcpSessionChannelDispatcher dispatcher = null; var serviceWorkerChannelItem = this._appServiceChannels.FirstOrDefault(c => c.Item1 == apportionDispatcher.GetAccessId()); if (!serviceWorkerChannelItem.IsNull() && _dispatchers.TryGetValue(serviceWorkerChannelItem.Item2, out dispatcher)) { this._appServiceChannels.Remove(serviceWorkerChannelItem); var serviceChannelDispatcher = dispatcher.ConvertTo <TcpSessionApplicationWorkerConnection>(); var appChannelDispatcher = apportionDispatcher.CreateApplicationWorkerChannelDispatcher(_dispatchers, ConnectionWorkType.ApplicationConnection); if (apportionDispatcher.ListByteBuffer.Count > 0) { var bufferData = apportionDispatcher.ListByteBuffer.ToArray(); appChannelDispatcher.ListByteBuffer.AddRange(bufferData); } this._dispatchers.Add(appChannelDispatcher.DispatcherId, appChannelDispatcher); this.OnConnectedEventHandler?.Invoke(appChannelDispatcher); if (!serviceChannelDispatcher.IsJoin) { serviceChannelDispatcher.Join(appChannelDispatcher); serviceChannelDispatcher.OnMessage(); appChannelDispatcher.OnMessage(); } else { appChannelDispatcher.CloseSession(); } } else { apportionDispatcher.CloseSession(); this.LogOutputEventHandler?.Invoke(LogOutLevelType.Debug, $"主控端应用工作连接未找到可匹配的应用服务工作连接!"); } }