Example #1
0
        /// <summary>
        /// Add a client to the arbiter, will raise the ClientAddedEvent if successful.
        /// </summary>
        public bool AddClient(IArbiterClient client)
        {
            if (client == null || GetClientByID(client.SubscriptionClientID, false) != null)
            {
                return(false);
            }

            if (_isDisposed)
            {// Possible to get disposed while operating here.
                return(false);
            }

            lock (_clientsAndFilters)
            {
                if (_clientsAndFilters.ContainsKey(client))
                {
                    return(false);
                }
                _clientsAndFilters.Add(client, client.SubscriptionMessageFilter);
            }

            lock (_clientsIdsAndClients)
            {
                _clientsIdsAndClients.Add(client.SubscriptionClientID, client);
            }

            if (client.ArbiterInitialize(this) == false || _isDisposed)
            {
                lock (_clientsAndFilters)
                {
                    _clientsAndFilters.Remove(client);
                }

                lock (_clientsIdsAndClients)
                {
                    _clientsIdsAndClients.Remove(client.SubscriptionClientID);
                }

                SystemMonitor.OperationError("Client failed arbiter initialialization [" + client.Name + "]");
                return(false);
            }

            ClientManagerClientUpdateDelegate clientAddedDelegate = ClientAddedEvent;

            if (clientAddedDelegate != null)
            {
                clientAddedDelegate(this, client);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Remove the client from the arbiter (will raise the ClientRemovedEvent if successful).
        /// </summary>
        public bool RemoveClient(IArbiterClient client)
        {
            if (_isDisposed)
            {// Possible to get disposed while operating here.
                return(false);
            }

            bool result = false;

            lock (_clientsAndFilters)
            {
                client.ArbiterUnInitialize();
                result = _clientsAndFilters.Remove(client) && _clientsIdsAndClients.Remove(client.SubscriptionClientID);
            }

            ClientManagerClientUpdateDelegate clientRemovedDelegate = ClientRemovedEvent;

            if (result && clientRemovedDelegate != null)
            {
                clientRemovedDelegate(this, client);
            }

            return(result);
        }