public void UnSubscribe <EnumType>(EnumType messageType, MessageCallback calllback) where EnumType : struct, System.IComparable, System.IConvertible, System.IFormattable { MessageCallbackWrapper toRemove = default(MessageCallbackWrapper); bool found = false; MessageMap mMap = null; if (_masterActionList.TryGetValue(typeof(EnumType), out mMap)) { MessageActionList mList = null; if (mMap.TryGetValue(messageType, out mList)) { foreach (MessageCallbackWrapper mCallback in mList) { if (mCallback.Callback == calllback) { toRemove = mCallback; found = true; break; } } if (found) { mList.Remove(toRemove); } } } }
private void MessageDelegate(object state) { MessageCallbackWrapper wrapper = (MessageCallbackWrapper)state; try { wrapper.Callback(wrapper.Agent, wrapper.Message); } catch (Exception ex) { m_log.Error("Async Message Event Handler: " + ex.Message, ex); } m_eventPool.Release(); }
/// <summary> /// Fire the events registered for this message type asynchronously /// </summary> /// <param name="incomingMessage">The incoming message</param> internal void BeginRaiseEvent(OSDMap incomingMessage, WSAgent agent) { MessageCallback callback; if (m_eventTable.TryGetValue(incomingMessage["Type"].AsString(), out callback) && callback != null) { while (!m_eventPool.WaitOne(Simian.LONG_SLEEP_INTERVAL)) { m_scheduler.ThreadKeepAlive(); } MessageCallbackWrapper wrapper = new MessageCallbackWrapper { Callback = callback, Message = incomingMessage, Agent = agent }; m_scheduler.FireAndForget(MessageDelegate, wrapper); } else { m_log.Debug("No handler registered for message type \"" + incomingMessage["Type"].AsString() + "\""); } }
/// <summary> /// Fire the events registered for this message type asynchronously /// </summary> /// <param name="incomingMessage">The incoming message</param> internal void BeginRaiseEvent(OSDMap incomingMessage, WSAgent agent) { MessageCallback callback; if (m_eventTable.TryGetValue(incomingMessage["Type"].AsString(), out callback) && callback != null) { while (!m_eventPool.WaitOne(Simian.LONG_SLEEP_INTERVAL)) m_scheduler.ThreadKeepAlive(); MessageCallbackWrapper wrapper = new MessageCallbackWrapper { Callback = callback, Message = incomingMessage, Agent = agent }; m_scheduler.FireAndForget(MessageDelegate, wrapper); } else { m_log.Debug("No handler registered for message type \"" + incomingMessage["Type"].AsString() + "\""); } }