Ejemplo n.º 1
0
        public IWampTopic CreateTopicByUri(string topicUri, bool persistent)
        {
            WampTopic wampTopic = CreateWampTopic(topicUri, persistent);

            IDictionary <string, WampTopic> casted = mTopicUriToSubject;

            casted.Add(topicUri, wampTopic);

            RaiseTopicCreated(wampTopic);

            return(wampTopic);
        }
Ejemplo n.º 2
0
        private WampTopic CreateWampTopic(string topicUri, bool persistent)
        {
            WampTopic topic = new WampTopic(topicUri, persistent);

            // Non persistent topics die when they are empty :)
            if (!persistent)
            {
                topic.TopicEmpty += OnTopicEmpty;
            }

            long subscriptionId = mSubscriptionIdToTopic.Add(topic);

            topic.SubscriptionId = subscriptionId;

            return(topic);
        }
Ejemplo n.º 3
0
        private void OnTopicEmpty(object sender, EventArgs e)
        {
            lock (mLock)
            {
                WampTopic topic = sender as WampTopic;

                if (!topic.HasSubscribers)
                {
                    topic.TopicEmpty -= OnTopicEmpty;
                    topic.Dispose();

                    mSubscriptionIdToTopic.TryRemoveExact(topic.SubscriptionId, topic);

                    if (mTopicUriToSubject.TryRemoveExact(topic.TopicUri, topic))
                    {
                        RaiseTopicRemoved(topic);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public IWampTopic GetOrCreateTopicByUri(string topicUri)
        {
            // Pretty ugly.
            bool created = false;

            WampTopic result =
                mTopicUriToSubject.GetOrAdd(topicUri,
                                            key =>
            {
                WampTopic topic = CreateWampTopic(topicUri, false);
                created         = true;
                return(topic);
            });

            if (created)
            {
                RaiseTopicCreated(result);
            }

            return(result);
        }