/// <summary> /// On arrival of a message which passes the given filter the caller /// will be notified though the given delegate. /// </summary> /// <param name="messageFilter">The message filter.</param> /// <param name="notifyAction">The action invoked when a matching message arrives.</param> public void ActOnArrival(IMessageFilter messageFilter, IMessageProcessAction notifyAction) { { Lokad.Enforce.Argument(() => messageFilter); Lokad.Enforce.Argument(() => notifyAction); } lock (m_Lock) { if (IsLastChanceProcessor(notifyAction)) { m_LastChanceProcessor = notifyAction; return; } if (!m_Filters.ContainsKey(messageFilter)) { m_Filters.Add(messageFilter, notifyAction); } } }
private static bool IsLastChanceProcessor(IMessageProcessAction notifyAction) { var attributes = notifyAction.GetType().GetCustomAttributes(typeof(LastChanceMessageHandlerAttribute), false); return(attributes.Length == 1); }