/// <summary>
        /// Triggers the start of the state-machine
        /// </summary>
        internal void Start()
        {
            //if IDLE then STARTING else exit
            if (Interlocked.CompareExchange(ref this._lifeCycleState, LifeCycleStateStarting, LifeCycleStateIdle) == LifeCycleStateIdle)
            {
                this._inboxSubject = this.NewInbox();
                this._inbox        = this._owner.SubPool.SubscribeInbox(this._inboxSubject + ".*", this);

                this._watchdogCts    = new CancellationTokenSource();
                this._watchdogThread = new Thread(this.WatchdogWorker);
                this._watchdogThread.Start();

                this._lifeCycleState = LifeCycleStateRunning;
            }
        }
Пример #2
0
        /// <summary>
        /// Entry-point to register a special INBOX subscription
        /// internally used for the request-reply mechanism.
        /// </summary>
        /// <param name="subject">The subject to subscribe to.</param>
        /// <param name="feedback">The reference to the reply message handler.</param>
        /// <returns>An instance of <see cref="InboxSubscription"/>.</returns>
        internal InboxSubscription SubscribeInbox(
            string subject,
            IRequestReplayFeedback feedback
            )
        {
            lock (this._sublocker)
            {
                //creates a new instance of subscription proxy
                this._ssid++;
                var sub = new InboxSubscription(this, this._ssid, subject, feedback);

                //then register it
                this._subRegister.Add(this._ssid, sub);

                //finally, enqueues the request of subscription to be
                //sent to the NATS broker.
                this._connmgr.EnqueueSubscriptionOperation(sub.ProtoMessageSub);
                return(sub);
            }
        }