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); } }
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, $"主控端应用工作连接未找到可匹配的应用服务工作连接!"); } }