/// <summary> /// Request a subscription for the specified instance /// </summary> /// <param name="instance">The instance asking for its subscription</param> /// <returns>True, if the subscription has been succeeded</returns> public bool Subscribe(IPortHeartbeat instance) { for (int i = 0; i < MaxSubscribers; i++) { if (this._subscriptions[i] == null) { //a free cell was found: fill it this._subscriptions[i] = instance; this.RecalcCount(); return(true); } } //no more free rooms return(false); }
/// <summary> /// Remove the subscription for the specified instance /// </summary> /// <param name="instance">The instance being unsubscribed</param> /// <returns>True, if the removal has been succeeded</returns> public bool Unsubscribe(IPortHeartbeat instance) { for (int i = 0; i < MaxSubscribers; i++) { if (this._subscriptions[i] == instance) { //subscription found: remove it this._subscriptions[i] = null; this.RecalcCount(); return(true); } } //no match was found return(false); }
/// <summary> /// The timer handler /// </summary> /// <param name="state">(not used)</param> private void TimerTick(object state) { //prevent spurious callbacks, once the timer has been disposed if (this._clock == null) { return; } lock (this._semaphore) { //scan for all the subscriptions for (int i = 0; i < this._optimizedCount; i++) { //check for a subscribed instance, enabled for notification IPortHeartbeat subscription = this._subscriptions[i]; if (subscription != null && subscription.IsEnabled) { subscription.Tick(); } } } }