MATSIM
EventsManagerModule.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * EventsManagerModule.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.events;
23 
24 import org.apache.commons.lang3.BooleanUtils;
28 
29 import jakarta.inject.Inject;
30 import jakarta.inject.Singleton;
31 import java.util.Set;
32 
33 public final class EventsManagerModule extends AbstractModule {
34 
35  @Override
36  public void install() {
37  if (BooleanUtils.isTrue(getConfig().eventsManager().getOneThreadPerHandler())) {
38  bindEventsManager().to(ParallelEventsManager.class).in(Singleton.class);
39  } else if (getConfig().eventsManager().getNumberOfThreads() != null) {
40  if (BooleanUtils.isTrue(getConfig().eventsManager().getSynchronizeOnSimSteps())) {
41  bindEventsManager().to(SimStepParallelEventsManagerImpl.class).in(Singleton.class);
42  } else {
43  bindEventsManager().to(ParallelEventsManagerImpl.class).in(Singleton.class);
44  }
45  } else {
46  bindEventsManager().to(SimStepParallelEventsManagerImpl.class).in(Singleton.class);
47  }
48  bind(EventHandlerRegistrator.class).asEagerSingleton();
49  }
50 
51  public static class EventHandlerRegistrator {
52  @Inject
53  EventHandlerRegistrator(EventsManager eventsManager, Set<EventHandler> eventHandlersDeclaredByModules) {
54  for (EventHandler eventHandler : eventHandlersDeclaredByModules) {
55  eventsManager.addHandler(eventHandler);
56  }
57  }
58  }
59 }
void addHandler(final EventHandler handler)
final com.google.inject.binder.LinkedBindingBuilder< EventsManager > bindEventsManager()