/// <summary>
        /// Links the publisher to a topic.
        /// </summary>
        /// <param name="publisherName">Name of the publisher.</param>
        /// <param name="topicName">Name of the topic.</param>
        /// <returns>PublisherClient instance.</returns>
        internal static PublisherClient LinkPublisherTopic(string publisherName, string topicName)
        {
            if (Utilities.IsNullOrWhiteSpace(publisherName))
            {
                throw new ArgumentNullException("publisherName", "Publisher name cannot be null or empty.");
            }

            if (Utilities.IsNullOrWhiteSpace(topicName))
            {
                throw new ArgumentNullException("topicName", "Topic name cannot be null or empty.");
            }

            PublisherClient publisher = GetOrCreatePublisher(publisherName);
            Topic           topic     = GetOrCreateTopic(topicName);

            publisher.AddTopicInternal(topic);
            topic.AddPublisherInternal(publisher);

            return(publisher);
        }
        /// <summary>
        /// Deletes the topic.
        /// </summary>
        /// <param name="topicName">Name of the topic.</param>
        public static void DeleteTopic(string topicName)
        {
            if (Utilities.IsNullOrWhiteSpace(topicName))
            {
                throw new ArgumentNullException("topicName", "Topic name cannot be null or empty.");
            }

            lock (Utilities.GetSyncRoot(Topics))
            {
                if (Topics.ContainsKey(topicName))
                {
                    Topic topic = Topics[topicName];

                    foreach (var publisherName in topic.Publishers)
                    {
                        topic.RemovePublisherInternal(publisherName);

                        PublisherClient publisher = GetPublisher(publisherName);

                        if (publisher != null)
                        {
                            publisher.RemoveTopicInternal(topicName);
                        }
                    }

                    foreach (var subscriptionName in topic.Subscriptions)
                    {
                        topic.RemovePublisherInternal(subscriptionName);

                        SubscriptionClient subscription = GetSubscription(subscriptionName);

                        if (subscription != null)
                        {
                            subscription.RemoveTopicInternal(topicName);
                        }
                    }

                    Topics.Remove(topicName);
                }
            }
        }
        /// <summary>
        /// Gets or creates a publisher.
        /// </summary>
        /// <param name="publisherName">Name of the publisher.</param>
        /// <returns>PublisherClient instance.</returns>
        public static PublisherClient GetOrCreatePublisher(string publisherName)
        {
            if (Utilities.IsNullOrWhiteSpace(publisherName))
            {
                throw new ArgumentNullException("publisherName", "Publisher name cannot be null or empty.");
            }

            lock (Utilities.GetSyncRoot(Publishers))
            {
                if (Publishers.ContainsKey(publisherName))
                {
                    return(Publishers[publisherName]);
                }
                else
                {
                    PublisherClient result = new PublisherClient(publisherName);

                    Publishers.Add(publisherName, result);

                    return(result);
                }
            }
        }