protected override void PreStart() { // crée un acteur enfant pour chacune des statistiques à surveiller // stat 1 { var actorStat1 = Context.ActorOf(Props.Create(() => new StatAvgTimeToSeeADoctorActor(_hospital)), ActorPaths.StatAvgTimeToSeeADoctorActorName); _hospitalStatActors[StatisticType.AvgTimeToSeeADoctor] = actorStat1; // l'acteur de statistique doit publier ses données vers l'acteur du "dashboard" _hospitalStatActors[StatisticType.AvgTimeToSeeADoctor].Tell(new SubscribeStatistic(StatisticType.AvgTimeToSeeADoctor, _dashboardActor)); } // stat 2 { var actorStat2 = Context.ActorOf(Props.Create(() => new StatAvgAppointmentDurationActor(_hospital)), ActorPaths.StatAvgAppointmentDurationActorName); _hospitalStatActors[StatisticType.AvgAppointmentDuration] = actorStat2; _hospitalStatActors[StatisticType.AvgAppointmentDuration].Tell(new SubscribeStatistic(StatisticType.AvgAppointmentDuration, _dashboardActor)); } // stat 3 { var actorStat3 = Context.ActorOf(Props.Create(() => new StatDiseaseActor(_hospital)), ActorPaths.StatDiseaseActorName); _hospitalStatActors[StatisticType.Illness] = actorStat3; _hospitalStatActors[StatisticType.Illness].Tell(new SubscribeStatistic(StatisticType.Illness, _dashboardActor)); } // stat 4 { var actorStat4 = Context.ActorOf(Props.Create(() => new StatEstimatedTimeToSeeADoctorActor(_hospital)), ActorPaths.StatEstimatedTimeToSeeADoctorActorName); _hospitalStatActors[StatisticType.EstimatedTimeToSeeADoctor] = actorStat4; _hospitalStatActors[StatisticType.EstimatedTimeToSeeADoctor].Tell(new SubscribeStatistic(StatisticType.EstimatedTimeToSeeADoctor, _dashboardActor)); } // crée un routeur pour broadcaster les messages vers les acteurs de statistiques _coordinatorActor = Context.ActorOf(Props.Empty.WithRouter(new BroadcastGroup( ActorPaths.GetActorPath(ActorType.StatAvgTimeToSeeADoctorActor, _hospital.Id), ActorPaths.GetActorPath(ActorType.StatAvgAppointmentDurationActor, _hospital.Id), ActorPaths.GetActorPath(ActorType.StatDiseaseActor, _hospital.Id), ActorPaths.GetActorPath(ActorType.StatEstimatedTimeToSeeADoctorActor, _hospital.Id))), "router"); // crée un acteur pour obtenir les événements de la BD et les propager dans le système d'acteurs. _eventFetcherActor = Context.ActorOf(Props.Create(() => new HospitalEventFetcherActor(_hospital)), ActorPaths.HospitalEventFetcherActorName); _eventFetcherActor.Tell(new SubscribeEventFetcher(_coordinatorActor)); base.PreStart(); }
private void Running() { Receive <Stat>(stat => { HandleStat(stat); }); Receive <TogglePause>(pause => { SetPauseButtonText(_pauseButton, paused: true); UnbecomeStacked(); // Stop fetching hospital events var commander = Context.ActorSelection(ActorPaths.GetActorPath(ActorType.Commander)); commander.Tell(new TogglePauseFetchingHospitalEvents()); }); }
private void Paused() { Receive <Stat>(stat => { HandleStat(stat); }); Receive <TogglePause>(pause => { SetPauseButtonText(_pauseButton, paused: false); BecomeStacked(Running); Stash.UnstashAll(); // Resume fetching hospital events var commander = Context.ActorSelection(ActorPaths.GetActorPath(ActorType.Commander)); commander.Tell(new TogglePauseFetchingHospitalEvents()); }); }
private Dictionary <int, IActorRef> InitializeHospitalCoordinatorActors(IEnumerable <Hospital> hospitals) { var coordinators = new Dictionary <int, IActorRef>(); foreach (var h in hospitals) { if (h == null) { continue; } var actor = Context.ActorOf(Props.Create(() => new HospitalCoordinatorActor(h, _dashboardActor)), ActorPaths.GetActorCoordinatorName(h.Id)); coordinators[h.Id] = actor; } return(coordinators); }