/// <summary> /// Handle SimulatePassingCar message. /// </summary> /// <param name="msg">The message to handle.</param> private void Handle(SimulatePassingCar msg) { // simulate car entry int entryLane = _rnd.Next(1, 4); ActorSelection entryCamera = Context.System.ActorSelection($"/user/entrycam{entryLane}"); DateTime entryTimestamp = DateTime.Now; VehiclePassed vehiclePassed = new VehiclePassed(msg.VehicleId, entryTimestamp); entryCamera.Tell(vehiclePassed); // simulate car exit int exitLane = _rnd.Next(1, 4); TimeSpan delay = TimeSpan.FromSeconds(_rnd.Next(_minExitDelayInS, _maxExitDelayInS) + _rnd.NextDouble()); DateTime exitTimestamp = entryTimestamp.Add(delay); ActorSelection exitCamera = Context.System.ActorSelection($"/user/exitcam{entryLane}"); vehiclePassed = new VehiclePassed(msg.VehicleId, exitTimestamp); Context.System.Scheduler.ScheduleTellOnce(delay, exitCamera, vehiclePassed, Self); // handle progress _carsSimulated++; if (_carsSimulated < _numberOfCars) { SimulatePassingCar simulatePassingCar = new SimulatePassingCar(GenerateRandomLicenseNumber()); Context.System.Scheduler.ScheduleTellOnce( _rnd.Next(_minEntryDelayInMS, _maxEntryDelayInMS), Self, simulatePassingCar, Self); } else { Self.Tell(new Shutdown()); } }
/// <summary> /// Handle VehiclePassed message /// </summary> /// <param name="msg">The message to handle.</param> private void Handle(VehiclePassed msg) { VehicleEntryRegistered vehicleEntryRegistered = new VehicleEntryRegistered(msg.VehicleId, msg.Timestamp); _trafficControlActor.Tell(vehicleEntryRegistered); }
private void Handle(VehiclePassed message) { var vehicleActor = Context.ActorSelection($"/user/traffic-control/*/vehicle-{message.Registration}"); vehicleActor.Tell(new VehicleExitRegistered(message.Registration, DateTime.Now.AddSeconds(440))); }
private void Handle(VehiclePassed message) { var trafficControlActor = Context.ActorSelection("/user/traffic-control"); trafficControlActor.Tell(new VehicleEntryRegistered(message.Registration, DateTime.Now)); }