From c5a71b9b458ccc5ef337e6b06585564402a1400f Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Tue, 23 Jan 2024 16:32:55 +0100 Subject: [PATCH] limit number of warnings --- .../freight/logistics/LSPControlerListener.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java b/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java index 01954cdf..86d0860d 100644 --- a/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java +++ b/src/main/java/org/matsim/freight/logistics/LSPControlerListener.java @@ -33,6 +33,7 @@ import org.matsim.core.controler.events.*; import org.matsim.core.controler.listener.*; import org.matsim.core.events.handler.EventHandler; +import org.matsim.core.gbl.Gbl; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierPlanWriter; import org.matsim.freight.carriers.Carriers; @@ -53,6 +54,9 @@ class LSPControlerListener private final Scenario scenario; private final List registeredHandlers = new ArrayList<>(); + private static int addListenerCnt = 0; + private static final int maxAddListenerCnt = 1; + @Inject private EventsManager eventsManager; @Inject private MatsimServices matsimServices; @Inject private LSPScorerFactory lspScoringFunctionFactory; @@ -60,6 +64,7 @@ class LSPControlerListener @Inject private OutputDirectoryHierarchy controlerIO; @Inject private CarrierAgentTracker carrierAgentTracker; + @Inject LSPControlerListener(Scenario scenario) { this.scenario = scenario; @@ -109,15 +114,20 @@ private void registerSimulationTrackers(HasSimulationTrackers hasSimulationTr hasSimulationTrackers.getSimulationTrackers()) { // ... register them ... if (!registeredHandlers.contains(simulationTracker)) { - log.warn("adding eventsHandler: " + simulationTracker); + log.info("adding eventsHandler: " + simulationTracker); eventsManager.addHandler(simulationTracker); registeredHandlers.add(simulationTracker); matsimServices.addControlerListener(simulationTracker); simulationTracker.setEventsManager(eventsManager); - } else { + } else if ( addListenerCnt < maxAddListenerCnt ){ log.warn("not adding eventsHandler since already added: " + simulationTracker); + addListenerCnt++; + if (addListenerCnt == maxAddListenerCnt) { + log.warn(Gbl.FUTURE_SUPPRESSED); + } } } + } @Override