SetEventTopic() публичный Метод

public SetEventTopic ( string key, Topic topic ) : void
key string
topic Topic
Результат void
        public virtual IDisposable Subscribe(ISubscriber subscriber, string cursor, Func <MessageResult, object, Task <bool> > callback, int maxMessages, object state)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException("subscriber");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            Subscription subscription = CreateSubscription(subscriber, cursor, callback, maxMessages, state);

            // Set the subscription for this subscriber
            subscriber.Subscription = subscription;

            var topics = new HashSet <Topic>();

            foreach (var key in subscriber.EventKeys)
            {
                // Create or retrieve topic and set it as HasSubscriptions
                Topic topic = SubscribeTopic(key);

                // Set the subscription for this topic
                subscription.SetEventTopic(key, topic);

                topics.Add(topic);
            }

            subscriber.EventKeyAdded   += _addEvent;
            subscriber.EventKeyRemoved += _removeEvent;
            subscriber.WriteCursor      = subscription.WriteCursor;

            var subscriptionState = new SubscriptionState(subscriber);
            var disposable        = new DisposableAction(_disposeSubscription, subscriptionState);

            // When the subscription itself is disposed then dispose it
            subscription.Disposable = disposable;

            // Add the subscription when it's all set and can be scheduled
            // for work. It's important to do this after everything is wired up for the
            // subscription so that publishes can schedule work at the right time.
            foreach (var topic in topics)
            {
                topic.AddSubscription(subscription);
            }

            subscriptionState.Initialized.Set();

            // If there's a cursor then schedule work for this subscription
            if (!String.IsNullOrEmpty(cursor))
            {
                _broker.Schedule(subscription);
            }

            return(disposable);
        }
Пример #2
0
        public virtual IDisposable Subscribe(ISubscriber subscriber, string cursor, Func <MessageResult, object, Task <bool> > callback, int maxMessages, object state)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException("subscriber");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            Subscription subscription = CreateSubscription(subscriber, cursor, callback, maxMessages, state);

            // Set the subscription for this subscriber
            subscriber.Subscription = subscription;

            var topics = new HashSet <Topic>();

            foreach (var key in subscriber.EventKeys)
            {
                Topic topic = GetTopic(key);

                // Set the subscription for this topic
                subscription.SetEventTopic(key, topic);

                topics.Add(topic);
            }

            subscriber.EventKeyAdded   += _addEvent;
            subscriber.EventKeyRemoved += _removeEvent;
            subscriber.WriteCursor      = subscription.WriteCursor;

            // Add the subscription when it's all set and can be scheduled
            // for work
            foreach (var topic in topics)
            {
                topic.AddSubscription(subscription);
            }

            var disposable = new DisposableAction(_disposeSubscription, subscriber);

            // When the subscription itself is disposed then dispose it
            subscription.Disposable = disposable;

            // If there's a cursor then schedule work for this subscription
            if (!String.IsNullOrEmpty(cursor))
            {
                _broker.Schedule(subscription);
            }

            return(disposable);
        }