public IObservableWithTask <ChangeNotification> ForChange(string groupName, string counterName) { if (string.IsNullOrWhiteSpace(groupName)) { throw new ArgumentException("Group name cannot be empty!"); } if (string.IsNullOrWhiteSpace(counterName)) { throw new ArgumentException("Counter name cannot be empty"); } var fullCounterName = CounterUtils.GetFullCounterName(groupName, counterName); var key = "counter-change/" + fullCounterName; var counter = GetOrAddConnectionState(key, "watch-counter-change", "unwatch-counter-change", () => watchedChanges.TryAdd(fullCounterName), () => watchedChanges.TryRemove(fullCounterName), fullCounterName); var taskedObservable = new TaskedObservable <ChangeNotification, CountersConnectionState>( counter, notification => string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase) && string.Equals(notification.CounterName, counterName, StringComparison.OrdinalIgnoreCase)); counter.OnChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <StartingWithNotification> ForCountersStartingWith(string groupName, string prefixForName) { if (string.IsNullOrWhiteSpace(groupName)) { throw new ArgumentException("Group name cannot be empty!"); } if (string.IsNullOrWhiteSpace(prefixForName)) { throw new ArgumentException("Prefix for counter name cannot be empty"); } var counterPrefix = CounterUtils.GetFullCounterName(groupName, prefixForName); var key = string.Concat("counters-starting-with/", counterPrefix); var counter = GetOrAddConnectionState(key, "watch-counters-prefix", "unwatch-counters-prefix", () => watchedPrefixes.TryAdd(counterPrefix), () => watchedPrefixes.TryRemove(counterPrefix), counterPrefix); var taskedObservable = new TaskedObservable <StartingWithNotification, CountersConnectionState>( counter, notification => { var t = string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase) && notification.CounterName.StartsWith(prefixForName, StringComparison.OrdinalIgnoreCase); return(t); }); counter.OnCountersStartingWithNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public void Send(ChangeNotification notification) { var counterPrefix = CounterUtils.GetFullCounterName(notification.GroupName, notification.CounterName); if (watchAllCounters > 0 || matchingChanges.Contains(counterPrefix)) { var value = new { Value = notification, Type = changeNotificationType }; enqueue(value); } if (matchingPrefixes.Any(prefix => counterPrefix.StartsWith(prefix))) { var value = new { Value = notification, Type = startingWithNotification }; enqueue(value); } if (matchingGroups.Contains(notification.GroupName)) { var value = new { Value = notification, Type = inGroupNotificationType }; enqueue(value); } }