Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// Triggered when a client is disconnected
        /// </summary>
        /// <param name="sender">indicating the client</param>
        /// <param name="e">indicating the event args</param>
        private void Client_ClientDisconnected(object sender, EventArgs e)
        {
            BrokerClient client = sender as BrokerClient;

            Debug.Assert(client != null, "[BrokerClientManager] ClientDisconnected Event: Sender should be the BrokerClient type.");
            BrokerTracing.TraceVerbose("[BrokerClientManager] Remove client {0}", client.ClientId);
            this.RemoveClient(client, false);
        }
Пример #3
0
        /// <summary>
        /// Add a new client
        /// </summary>
        /// <param name="clientId">indicating the client id</param>
        /// <returns>return the new client</returns>
        private BrokerClient AddNewClient(string clientId, string userName)
        {
            BrokerClient client = new BrokerClient(clientId, userName, this.queueFactory, this.observer, this.stateManager, this.monitor, this.sharedData);

            client.AllRequestDone     += new EventHandler(this.Client_AllRequestDone);
            client.ClientDisconnected += new EventHandler(this.Client_ClientDisconnected);
            this.clientDic.Add(clientId, client);
            BrokerTracing.TraceVerbose("[BrokerClientManager] Add new client {0}", clientId);
            this.stateManager.ClientConnected();
            this.monitor.ClientConnected();
            return(client);
        }
Пример #4
0
        /// <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);
            }
        }