/// <summary> /// Remove a client from the client manager /// Thread safe /// </summary> /// <param name="client">indicating the client</param> /// <param name="purge">indicating whether the client needs purge</param> private SessionPersistCounter RemoveClient(BrokerClient client, bool purge) { bool flag; SessionPersistCounter counter = null; lock (this.clientDic) { client.AllRequestDone -= new EventHandler(this.Client_AllRequestDone); client.ClientDisconnected -= new EventHandler(this.Client_ClientDisconnected); // Remove the client from client dic this.clientDic.Remove(client.ClientId); if (purge) { counter = client.DeleteQueue(); } client.Dispose(); flag = this.clientDic.Count == 0; } if (flag) { this.stateManager.AllClientsDisconnected(); } this.CheckIfAllRequestDone(); return(counter); }
/// <summary> /// Purge the client /// </summary> /// <param name="clientId">indicating the client id</param> /// <param name="userName">indicating the user name</param> public async Task PurgeClient(string clientId, string userName) { BrokerClient client = this.GetClient(clientId, userName); SessionPersistCounter counter = this.RemoveClient(client, true); if (counter != null) { await this.monitor.ClientPurged(counter.FlushedRequestsCount, counter.FailedRequestsCountField, counter.ResponsesCountField); } }
/// <summary> /// remove the storage. /// </summary> public SessionPersistCounter Close() { BrokerTracing.TraceVerbose("[MemoryPersist] .Close: Close the MemoryPersist."); if (!this.isClosedField) { this.isClosedField = true; } SessionPersistCounter counter = new SessionPersistCounter(); counter.ResponsesCountField = Interlocked.Read(ref this.responseCountField); counter.FailedRequestsCountField = Interlocked.Read(ref this.failedRequestCountField); return(counter); }
/// <summary> /// Delete the correspoding queue /// </summary> public SessionPersistCounter DeleteQueue() { SessionPersistCounter counter = null; if (this.queue != null) { this.queue.OnEvent -= this.Queue_OnEvent; this.queue.OnPutResponsesSuccessEvent -= this.Queue_OnPutResponsesSuccessEvent; this.queue.OnFatalExceptionEvent -= this.Queue_OnFatalExceptionEvent; counter = this.queue.Close(); this.queue = null; } // Send client purged when delete queue if (this.responsesClient != null) { this.responsesClient.ClientDisconnect(true); } return(counter); }