public void TopicStateHasSubscriptions() { var topic = new Topic(100, TimeSpan.Zero); topic.AddSubscription(new Mock<ISubscription>().Object); Assert.Equal(TopicState.HasSubscriptions, topic.State); }
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); }
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); }
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; } }
public virtual void SetEventTopic(string key, Topic topic) { AddEvent(key, topic); }
public void TopicStateCreated() { var topic = new Topic(100, TimeSpan.Zero); Assert.Equal(TopicState.NoSubscriptions, topic.State); }
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(); } }
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); } }
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); } } }
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; } }
public virtual void SetEventTopic(string key, Topic topic) { // Don't call AddEvent since that's virtual AddEventCore(key); }
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; } } }
public virtual bool AddEvent(string key, Topic topic) { lock (EventKeys) { if (EventKeys.Contains(key)) { return false; } EventKeys.Add(key); return true; } }
public virtual void SetEventTopic(string key, Topic topic) { lock (EventKeys) { EventKeys.Add(key); } }
public virtual bool AddEvent(string key, Topic topic) { lock (EventKeys) { return EventKeys.Add(key); } }
public void TopicStateCreated() { var topic = new Topic(100, TimeSpan.Zero); Assert.Equal(TopicState.Created, topic.State); }
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; } } }
public virtual bool AddEvent(string key, Topic topic) { return AddEventCore(key); }
private static ulong GetMessageId(Topic topic) { if (topic == null) { return 0; } return topic.Store.GetMessageCount(); }
public virtual bool AddEvent(string key, Topic topic) { return(AddEventCore(key)); }