private void AsyncRaisesEvent(TEvent evnt, EventObservation <TEvent> observation) { Task.Factory.StartNew(() => { observation.EventHandler(evnt); }); }
private EventObservation <TEvent> NewObservation(Type eventType, SubscriptionId subscriptionId, SourceId sourceId, Action <TEvent> eventHandler) { Log.Debug("Acquired lock to ActiveObservations at method NewSubscriptionFor(...)"); var observation = new EventObservation <TEvent>(eventType, subscriptionId, sourceId, eventHandler); lock (ActiveObservations) { ActiveObservations[new Tuple <Type, SubscriptionId, SourceId>(eventType, subscriptionId, sourceId)] = observation; } Log.Debug("Released lock to ActiveObservations at method NewSubscriptionFor(...)"); return(observation); }
private void RemoveObservation(EventObservation <TEvent> observation) { if (observation == null) { return; } Log.Debug("Acquired lock to ActiveObservations at method RemoveSubscription(...)"); lock (ActiveObservations) { ActiveObservations.Remove(new Tuple <Type, SubscriptionId, SourceId>(observation.EventType, observation.SubscriptionId, observation.SourceId)); } Log.Debug("Released lock to ActiveObservations at method RemoveSubscription(...)"); }
private EventObservation <TEvent> ExistingObservation(Type eventType, SubscriptionId subscriptionId, SourceId sourceId) { Log.Debug("Acquired lock to ActiveObservations at method ExistingSubscriptionFor(...)"); try { lock (ActiveObservations) { EventObservation <TEvent> observation = null; ActiveObservations.TryGetValue(new Tuple <Type, SubscriptionId, SourceId>(eventType, subscriptionId, sourceId), out observation); return(observation); } } catch (Exception e) { Log.Error(String.Format("Exception at method ExistingSubscriptionFor(...) - messageType '{0}' subscription '{1}' source {2}", eventType, subscriptionId, sourceId), e); throw e; } finally { Log.Debug("Released lock to ActiveObservations at method ExistingSubscriptionFor(...)"); } }
public void Observe(EventObservation <TEvent> eventObservation) { Observe(eventObservation.EventType, eventObservation.EventHandler, eventObservation.SubscriptionId, eventObservation.SourceId); }