public PerformanceCounterCoordinatorActor(IActorRef chartingActor, Dictionary <CounterType, IActorRef> counterActors)
        {
            _chartingActor = chartingActor;
            _counterActors = counterActors;

            Receive <Watch>(watch =>
            {
                if (!_counterActors.ContainsKey(watch.Counter))
                {
                    var counterActor = Context.ActorOf(Props.Create(() =>
                                                                    new PerformanceCounterActor(watch.Counter.ToString(), CounterGenerators[watch.Counter])));

                    _counterActors[watch.Counter] = counterActor;
                }

                _chartingActor.Tell(new ChartingActor.AddSeries(CounterSeries[watch.Counter]()));

                _counterActors[watch.Counter].Tell(new SubscribeCounter(watch.Counter, _chartingActor));
            });

            Receive <Unwatch>(unwatch =>
            {
                if (!_counterActors.ContainsKey(unwatch.Counter))
                {
                    return;
                }

                ActorRefImplicitSenderExtensions.Tell(_counterActors[unwatch.Counter], new UnsubscribeCounter(unwatch.Counter, _chartingActor));

                _chartingActor.Tell(new ChartingActor.RemoveSeries(unwatch.Counter.ToString()));
            });
        }
Example #2
0
        private void HandleWatch(Watch watch)
        {
            var counterType = watch.CounterType;

            if (!this._counterActors.ContainsKey(counterType))
            {
                var counterActor = Context.ActorOf(Props.Create(() =>
                                                                new PerformanceCounterActor(counterType.ToString(), CounterGenerators[counterType])));
                this._counterActors[counterType] = counterActor;
            }

            this._chartingActor.Tell(new ChartingActor.AddSeries(CounterSeries[counterType]()));
            this._counterActors[counterType].Tell(new SubscribeCounter(counterType, this._chartingActor));
        }