コード例 #1
0
        public void TopicStateHasSubscriptions()
        {
            var topic = new Topic(100, TimeSpan.Zero);

            topic.AddSubscription(new Mock<ISubscription>().Object);

            Assert.Equal(TopicState.HasSubscriptions, topic.State);
        }
コード例 #2
0
        public void TopicStateNoSubscriptions()
        {
            var topic = new Topic(100, TimeSpan.Zero);
            var mock = new Mock<ISubscription>();
            mock.Setup(m => m.Identity).Returns("1");

            topic.AddSubscription(mock.Object);
            topic.RemoveSubscription(mock.Object);

            Assert.Equal(TopicState.NoSubscriptions, topic.State);
        }
コード例 #3
0
        public void TopicStateHasSubscriptionsIfMoreThanOne()
        {
            var topic = new Topic(100, TimeSpan.Zero);
            var sub1 = new Mock<ISubscription>();
            sub1.Setup(m => m.Identity).Returns("1");

            topic.AddSubscription(new Mock<ISubscription>().Object);
            topic.AddSubscription(sub1.Object);
            topic.RemoveSubscription(sub1.Object);

            Assert.Equal(TopicState.HasSubscriptions, topic.State);
        }
コード例 #4
0
ファイル: DefaultSubscription.cs プロジェクト: stirno/SignalR
        public override bool AddEvent(string eventKey, Topic topic)
        {
            lock (_lockObj)
            {
                // O(n), but small n and it's not common
                var index = _cursors.FindIndex(c => c.Key == eventKey);
                if (index == -1)
                {
                    _cursors.Add(new Cursor(eventKey, GetMessageId(topic), _stringMinifier.Minify(eventKey)));

                    _cursorTopics.Add(topic);

                    return true;
                }

                return false;
            }
        }
コード例 #5
0
 public virtual void SetEventTopic(string key, Topic topic)
 {
     AddEvent(key, topic);
 }
コード例 #6
0
 public void TopicStateCreated()
 {
     var topic = new Topic(100, TimeSpan.Zero);
     Assert.Equal(TopicState.NoSubscriptions, topic.State);
 }
コード例 #7
0
ファイル: MessageBus.cs プロジェクト: eduaglz/SignalR-Server
        private void ScheduleTopic(Topic topic)
        {
            try
            {
                topic.SubscriptionLock.EnterReadLock();

                for (int i = 0; i < topic.Subscriptions.Count; i++)
                {
                    ISubscription subscription = topic.Subscriptions[i];
                    _broker.Schedule(subscription);
                }
            }
            finally
            {
                topic.SubscriptionLock.ExitReadLock();
            }
        }
コード例 #8
0
ファイル: MessageBus.cs プロジェクト: eduaglz/SignalR-Server
        private void DestroyTopicCore(string key, Topic topic)
        {
            Topics.TryRemove(key);
            _stringMinifier.RemoveUnminified(key);

            Counters.MessageBusTopicsCurrent.Decrement();

            _logger.LogInformation("RemoveTopic(" + key + ")");

            if (AfterTopicGarbageCollected != null)
            {
                AfterTopicGarbageCollected(key, topic);
            }
        }
コード例 #9
0
ファイル: MessageBus.cs プロジェクト: eduaglz/SignalR-Server
 private void DestroyTopic(string key, Topic topic)
 {
     // The goal of this function is to destroy topics after 2 garbage collect cycles
     // This first if statement will transition a topic into the dying state on the first GC cycle
     // but it will prevent the code path from hitting the second if statement
     if (Interlocked.CompareExchange(ref topic.State, TopicState.Dying, TopicState.NoSubscriptions) == TopicState.Dying)
     {
         // If we've hit this if statement we're on the second GC cycle with this soon to be
         // destroyed topic.  At this point we move the Topic State into the Dead state as
         // long as it has not been revived from the dying state.  We check if the state is
         // still dying again to ensure that the topic has not been transitioned into a new
         // state since we've decided to destroy it.
         if (Interlocked.CompareExchange(ref topic.State, TopicState.Dead, TopicState.Dying) == TopicState.Dying)
         {
             DestroyTopicCore(key, topic);
         }
     }
 }
コード例 #10
0
ファイル: MessageBus.cs プロジェクト: stirno/SignalR
        private void DestroyTopic(string key, Topic topic)
        {
            var state = Interlocked.Exchange(ref topic.State, TopicState.Dead);

            switch (state)
            {
                case TopicState.NoSubscriptions:
                    DestroyTopicCore(key, topic);
                    break;
                default:
                    // Restore the old state
                    Interlocked.Exchange(ref topic.State, state);
                    break;
            }
        }
コード例 #11
0
ファイル: Subscription.cs プロジェクト: fanikiwa/SignalR-dev
 public virtual void SetEventTopic(string key, Topic topic)
 {
     // Don't call AddEvent since that's virtual
     AddEventCore(key);
 }
コード例 #12
0
        public override void SetEventTopic(string eventKey, Topic topic)
        {
            base.SetEventTopic(eventKey, topic);

            lock (_cursors)
            {
                // O(n), but small n and it's not common
                var index = FindCursorIndex(eventKey);
                if (index != -1)
                {
                    _cursorTopics[index] = topic;
                }
            }
        }
コード例 #13
0
        public virtual bool AddEvent(string key, Topic topic)
        {
            lock (EventKeys)
            {
                if (EventKeys.Contains(key))
                {
                    return false;
                }

                EventKeys.Add(key);
                return true;
            }
        }
コード例 #14
0
ファイル: Subscription.cs プロジェクト: stirno/SignalR
 public virtual void SetEventTopic(string key, Topic topic)
 {
     lock (EventKeys)
     {
         EventKeys.Add(key);
     }
 }
コード例 #15
0
ファイル: Subscription.cs プロジェクト: stirno/SignalR
 public virtual bool AddEvent(string key, Topic topic)
 {
     lock (EventKeys)
     {
         return EventKeys.Add(key);
     }
 }
コード例 #16
0
ファイル: TopicFacts.cs プロジェクト: kaushalp/SignalR-Server
 public void TopicStateCreated()
 {
     var topic = new Topic(100, TimeSpan.Zero);
     Assert.Equal(TopicState.Created, topic.State);
 }
コード例 #17
0
ファイル: DefaultSubscription.cs プロジェクト: stirno/SignalR
 public override void SetEventTopic(string eventKey, Topic topic)
 {
     lock (_lockObj)
     {
         // O(n), but small n and it's not common
         var index = _cursors.FindIndex(c => c.Key == eventKey);
         if (index != -1)
         {
             _cursorTopics[index] = topic;
         }
     }
 }
コード例 #18
0
ファイル: Subscription.cs プロジェクト: Djohnnie/Sonarr
 public virtual bool AddEvent(string key, Topic topic)
 {
     return AddEventCore(key);
 }
コード例 #19
0
ファイル: Subscription.cs プロジェクト: Djohnnie/Sonarr
 public virtual void SetEventTopic(string key, Topic topic)
 {
     // Don't call AddEvent since that's virtual
     AddEventCore(key);
 }
コード例 #20
0
        private static ulong GetMessageId(Topic topic)
        {
            if (topic == null)
            {
                return 0;
            }

            return topic.Store.GetMessageCount();
        }
コード例 #21
0
ファイル: Subscription.cs プロジェクト: fanikiwa/SignalR-dev
 public virtual bool AddEvent(string key, Topic topic)
 {
     return(AddEventCore(key));
 }