public int BuildHandlerChain(Event e, EventEquivalent equivalent, List <Handler> handlerChain) { rwlock.EnterReadLock(); try { Event.Tag tag = (Event.Tag)e.GetTypeTag(); Fingerprint fingerprint = e.GetFingerprint(); while (tag != null) { int typeId = tag.TypeId; IList <Slot> slots = filter.Get(typeId); if (slots != null) { for (int i = 0, count = slots.Count; i < count; ++i) { var slot = slots[i]; if (slot.Equivalent(fingerprint)) { equivalent.InnerEvent = e; equivalent.SetFingerprint(slot); equivalent.InnerTypeId = typeId; HandlerSet handlers; if (handlerMap.TryGetValue(equivalent, out handlers)) { IList <Handler> list = handlers.GetList(); for (int j = 0, jCount = list.Count; j < jCount; ++j) { handlerChain.Add(list[j]); } } } } } tag = (Event.Tag)tag.Base; } // sort result return(handlerChain.Count); } finally { rwlock.ExitReadLock(); } }
private void Run() { currentFlow = this; if ((object)queue != null) { equivalent = new EventEquivalent(); handlerChain = new List <Handler>(); } BeginInternal(); while (!shouldStop) { UpdateInternal(); if (queue != null) { while ((DateTime.UtcNow.Ticks - Time.CurrentTicks) < Resolution) { Event e; if (queue.TryDequeue(out e)) { Dispatch(e); if (e.GetTypeId() == (int)BuiltinEventType.FlowStop) { break; } } else { if (shouldStop) { break; } else { Thread.Sleep(1); continue; } } } } else { var tickDelta = DateTime.UtcNow.Ticks - Time.CurrentTicks; var delay = (tickDelta < Resolution ? (int)((Resolution - tickDelta) / Time.TicksInMillisecond) : 0); Thread.Sleep(delay); } } End(); if (queue != null) { handlerChain = null; equivalent = null; } currentFlow = null; }