Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
limit number of warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Jan 23, 2024
1 parent b25da0d commit c5a71b9
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,13 +54,17 @@ class LSPControlerListener
private final Scenario scenario;
private final List<EventHandler> 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;
@Inject @Nullable private LSPStrategyManager strategyManager;
@Inject private OutputDirectoryHierarchy controlerIO;
@Inject private CarrierAgentTracker carrierAgentTracker;


@Inject
LSPControlerListener(Scenario scenario) {
this.scenario = scenario;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c5a71b9

Please sign in to comment.