Пример #1
0
        internal void ReregisterSubscribers(TopicSearchOptions searchOption)
        {
            try
            {
                _readerWriterLock.AcquireReaderLock(Timeout.Infinite);

                if (_isDisposed)
                {
                    return;
                }

                lock (_subscriptions)
                {
                    switch (searchOption)
                    {
                    case TopicSearchOptions.ByName:

                        foreach (KeyValuePair <SubscriptionIdentifier, TopicSubscription> subscriptions in _subscriptions)
                        {
                            _cacheImpl.Subscribe(Name, subscriptions.Value.SubscriptionName, SubscriptionType.Subscriber, subscriptions.Value.CreationTime, subscriptions.Value.Expiration, subscriptions.Value.GetSubscriptionPolicyType);
                        }
                        break;
                    }
                }
            }
            finally
            {
                _readerWriterLock.ReleaseReaderLock();
            }
        }
Пример #2
0
        public TopicIdentity(string topicName, TopicSearchOptions searchOption)
        {
            if (topicName == null)
            {
                throw new ArgumentNullException(nameof(topicName));
            }

            this.TopicName    = topicName;
            this.SearchOption = searchOption;
        }
Пример #3
0
        public ITopic GetTopic(string topicName)

        {
            TopicSearchOptions searchOptions = TopicSearchOptions.ByName;

            if (string.IsNullOrEmpty(topicName))
            {
                throw new ArgumentException("TopicName is null or empty string");
            }
            TopicIdentity topicPair = new TopicIdentity(topicName, TopicSearchOptions.ByName);

            return(PubSubManager.GetOrCreateTopic(topicPair, TopicOperationType.Get, false));
        }
Пример #4
0
        internal ITopic GetOrCreateTopic(TopicIdentity topicPair, TopicOperationType type, bool internalOperation)
        {
            if (string.IsNullOrEmpty(topicPair.TopicName))
            {
                throw new ArgumentException("TopicName is null or empty string");
            }


            if (!internalOperation && IsDefaultTopicName(topicPair.TopicName))
            {
                throw new OperationFailedException(ErrorCodes.PubSub.DEFAULT_TOPICS, ErrorMessages.GetErrorMessage(ErrorCodes.PubSub.DEFAULT_TOPICS));
            }

            if (_cacheImpl == null)
            {
                throw new OperationFailedException(ErrorCodes.CacheInit.CACHE_NOT_INIT, ErrorMessages.GetErrorMessage(ErrorCodes.CacheInit.CACHE_NOT_INIT));
            }

            Topic topic = null;

            if (_cacheImpl.GetOrCreate(topicPair.TopicName, type))
            {
                lock (this)
                {
                    if (_topicsDic.TryGetValue(topicPair, out topic))
                    {
                        if (topic.IsClosed)
                        {
                            _topicsDic.TryRemove(topicPair, out topic);
                            TopicSearchOptions searchOptions = topic.SearchOptions;
                            topic = new Topic(topicPair.TopicName, _cacheImpl, _perfStatsCollector, this);
                            topic.SearchOptions = searchOptions;
                        }

                        topic.IncrementRefCount();
                        return(topic);
                    }

                    topic = new Topic(topicPair.TopicName, _cacheImpl, _perfStatsCollector, this);

                    topic.IncrementRefCount();
                    _topicsDic.TryAdd(topicPair, topic);
                }
            }
            return(topic);
        }