public void AddCar(Car car) { foreach (var group in _groups) { if (group.Value.Cars.Count() < _carsPerProcessor) { group.Value.Cars.Add(car); return; } } CreateGroup(new List<Car> { car }); }
public void Enqueue(Message message, Car car, Priority priority = Priority.Low) { MessageQueue queue; if (_queueLookup.TryGetValue(car, out queue)) { queue.Add(message, priority); } }
private void RemoveCarFromGroup(Car car) { foreach (var group in _groups) { Car carToRemove = null; foreach (var trackedCar in @group.Value.Cars) { if (trackedCar == car) { carToRemove = trackedCar; } } if (carToRemove != null) { group.Value.Cars.Remove(carToRemove); } } }
public void RemoveCar(Car car) { _queueLookup.Remove(car); RemoveCarFromGroup(car); RemoveUnNeededGroups(); }