/// <summary> /// on connected /// </summary> /// <param name="node"></param> /// <param name="connection"></param> private void OnConnected(SocketConnector node, SocketBase.IConnection connection) { //fire connected event. this.Connected(node.Name, connection); bool isActive = false; lock (this) if (this._dicNodes.ContainsKey(node.Name)) { isActive = true; this._dicConnections[node.Name] = connection; this._arrConnections = this._dicConnections.Values.ToArray(); this._hashConnections = new ConsistentHashContainer <SocketBase.IConnection>(this._dicConnections); } if (isActive) { this.ServerAvailable(node.Name, connection); } else { connection.BeginDisconnect(); } }
/// <summary> /// on disconnected /// </summary> /// <param name="node"></param> /// <param name="connection"></param> private void OnDisconnected(SocketConnector node, SocketBase.IConnection connection) { lock (this) { if (!this._dicConnections.Remove(node.Name)) { return; } this._arrConnections = this._dicConnections.Values.ToArray(); this._hashConnections = new ConsistentHashContainer <SocketBase.IConnection>(this._dicConnections); } }
/// <summary> /// 当客户端与服务器建立连接成功时发生的事件处理 /// </summary> /// <param name="node"></param> /// <param name="connection"></param> private void OnConnected(SocketConnector node, SocketBase.IConnection connection) { //fire connected event. this.Connected(node.Name, connection); bool isActive = false; SocketBase.IConnection oldConnection = null; lock (this) { //remove exists connection by name. if (this._dicConnections.TryGetValue(node.Name, out oldConnection)) { this._dicConnections.Remove(node.Name); } //add curr connection to list if node is active if (isActive = this._dicNodes.ContainsKey(node.Name)) { this._dicConnections[node.Name] = connection; } this._arrConnections = this._dicConnections.Values.ToArray(); this._hashConnections = new ConsistentHashContainer <SocketBase.IConnection>(this._dicConnections); } //disconect old connection. if (oldConnection != null) { oldConnection.BeginDisconnect(); } //disconnect not active node connection. if (!isActive) { connection.BeginDisconnect(); } //fire server available event. if (isActive && this.ServerAvailable != null) { this.ServerAvailable(node.Name, connection); } }
/// <summary> /// on disconnected /// </summary> /// <param name="node"></param> /// <param name="connection"></param> private void OnDisconnected(SocketConnector node, SocketBase.IConnection connection) { lock (this) { if (!this._dicConnections.Remove(node.Name)) return; this._arrConnections = this._dicConnections.Values.ToArray(); this._hashConnections = new ConsistentHashContainer<SocketBase.IConnection>(this._dicConnections); } }
/// <summary> /// on connected /// </summary> /// <param name="node"></param> /// <param name="connection"></param> private void OnConnected(SocketConnector node, SocketBase.IConnection connection) { //fire connected event. this.Connected(node.Name, connection); bool isActive = false; SocketBase.IConnection oldConnection = null; lock (this) { //remove exists connection by name. if (this._dicConnections.TryGetValue(node.Name, out oldConnection)) this._dicConnections.Remove(node.Name); //add curr connection to list if node is active if (isActive = this._dicNodes.ContainsKey(node.Name)) this._dicConnections[node.Name] = connection; this._arrConnections = this._dicConnections.Values.ToArray(); this._hashConnections = new ConsistentHashContainer<SocketBase.IConnection>(this._dicConnections); } //disconect old connection. if (oldConnection != null) oldConnection.BeginDisconnect(); //disconnect not active node connection. if (!isActive) connection.BeginDisconnect(); //fire server available event. if (isActive && this.ServerAvailable != null) this.ServerAvailable(node.Name, connection); }
/// <summary> /// on connected /// </summary> /// <param name="node"></param> /// <param name="connection"></param> private void OnConnected(SocketConnector node, SocketBase.IConnection connection) { SocketBase.IConnection oldConnection = null; bool isActive = false; //node is active lock (this) { //remove exists connection by name. if (this._dicConnections.TryGetValue(node.Name, out oldConnection)) this._dicConnections.Remove(node.Name); isActive = this._dicNodes.ContainsKey(node.Name); if (isActive) this._dicConnections[node.Name] = connection; this._arrConnections = this._dicConnections.Values.ToArray(); this._hashConnections = new ConsistentHashContainer<SocketBase.IConnection>(this._dicConnections); } //disconect old connection. if (oldConnection != null) oldConnection.BeginDisconnect(); //disconnect not active node connection. if (!isActive) { connection.BeginDisconnect(); return; } //fire connected event. this.Connected(node.Name, connection); }