MATSIM
MobsimScopeEventHandling.java
Go to the documentation of this file.
1 /*
2  * *********************************************************************** *
3  * project: org.matsim.*
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2020 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** *
19  */
20 
21 package org.matsim.core.events;
22 
23 import java.util.Collection;
24 import java.util.concurrent.ConcurrentLinkedQueue;
25 
26 import jakarta.inject.Inject;
27 import jakarta.inject.Singleton;
28 
32 
39 @Singleton
41  private final Collection<MobsimScopeEventHandler> eventHandlers = new ConcurrentLinkedQueue<>();
43 
44  @Inject
45  public MobsimScopeEventHandling(EventsManager eventsManager) {
46  this.eventsManager = eventsManager;
47  }
48 
50  eventHandlers.add(handler);
51  eventsManager.addHandler(handler);
52  }
53 
54  @Override
55  public void notifyAfterMobsim(AfterMobsimEvent event) {
56  eventHandlers.forEach(eventsManager::removeHandler);
57  eventHandlers.forEach(eventHandler -> eventHandler.cleanupAfterMobsim(event.getIteration()));
58  eventHandlers.clear();
59  }
60 }
final Collection< MobsimScopeEventHandler > eventHandlers
void addHandler(final EventHandler handler)
void addMobsimScopeHandler(MobsimScopeEventHandler handler)