예제 #1
0
        /// <summary>
        /// Subscribes the specified observer.
        /// </summary>
        /// <param name="observer">The observer.</param>
        /// <returns>An IDisposable.</returns>
        public IDisposable Subscribe(IObserver <T> observer)
        {
            if (_theObserver != null)
            {
                throw new InvalidOperationException(
                          "There should be only one observer attached to the Firehose Observable");
            }

            var messageTransportWaitCallBackId = Guid.Empty;

            try
            {
                _theObserver = observer;
                var topicObserver = new TopicObserver(_topic, observer);
                topicObserver.Start();

                return
                    (Disposable.Create(
                         () => topicObserver.Stop()));
            }
            catch (Exception ex)
            {
                Tracer.TraceSource.TraceEvent(
                    TraceEventType.Error,
                    0,
                    "Fire hose observable - topic:{0}, waitCallbackId:{1}, unable to subscribe to fire hose observable - {2}",
                    _topic,
                    messageTransportWaitCallBackId,
                    ex);

                throw;
            }
        }
 protected override void OnStart()
 {
     base.OnStart();
     _topicObserver.Start();
     Params.Subscriptions.Add(new Subscription(_scheduler.Now.Ticks));
     _subscriptionIndex = Params.Subscriptions.Count - 1;
 }