/// <summary> /// Method used to fire a Summon event. /// </summary> /// <param name="e">The event arguments.</param> private void OnSummon(JudgeSummonEventArgs e) { if (this.Summon != null) { this.Summon(this, e); } }
/// <summary> /// Thread safe. Calling the dispatch method can trigger the Summon /// event if there is no Judge available in the pool. If this /// is the case, it is assumed that a Summon event handler will create /// a Judge and asign it to the SummonEventArgs.Respondent property. /// Otherwise, return an existing Judge from the pool. /// </summary> /// <returns>A Judge available to answer the call.</returns> public Judge Dispatch() { Judge judge = null; lock (this.judgePool) { if (this.judgePool.Count == 0) { JudgeSummonEventArgs e = new JudgeSummonEventArgs(); this.OnSummon(e); if (e.Respondent == null) { throw new InvalidOperationException("The Judge summoning returned null."); } this.judgePool.Push(e.Respondent); } judge = this.judgePool.Pop(); this.dispatchedJudges.Add(judge.GetHashCode()); } return judge; }