MATSIM
QNetsimEngineModule.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * QNetsimEngineModule.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.mobsim.qsim.qnetsimengine;
23 
24 import com.google.inject.Singleton;
25 import com.google.inject.multibindings.Multibinder;
28 
29 public final class QNetsimEngineModule extends AbstractQSimModule {
30  public final static String COMPONENT_NAME = "NetsimEngine";
31 
39  @Override
40  protected void configureQSim() {
41  // === QNetsimEngine:
42 
43  bind(QNetsimEngineI.class).to(QNetsimEngineWithThreadpool.class).in( Singleton.class );
44  // (given the "overriding" architecture, this is a default binding which may be overridden later)
45 
46  addQSimComponentBinding( COMPONENT_NAME ).to( QNetsimEngineI.class );
47  // (this will register the MobsimEngine functionality. necessary since QNetsimEngineI is a MobsimEngine, which needs to be registered.)
48 
49  // === QNetworkFactory:
50 
51  if ( this.getConfig().qsim().isUseLanes() ) {
52  bind( DefaultQNetworkFactory.class ).in( Singleton.class );
53  // (provide this as a delegate to QLanesNetworkFactory)
54  bind(QNetworkFactory.class).to( QLanesNetworkFactory.class ).in( Singleton.class ) ;
55  } else {
56  bind(QNetworkFactory.class).to( DefaultQNetworkFactory.class ).in( Singleton.class) ;
57  }
58 
59  // === LinkSpeedCalculator(s):
60 
61  Multibinder.newSetBinder( this.binder(), LinkSpeedCalculator.class );
62  // (initialize this here so we do not have to hedge against "null".)
63 
64 // addLinkSpeedCalculatorBinding().to(...);
65 
66  // === departure handler:
67  bind( NetworkModeDepartureHandler.class ).to(NetworkModeDepartureHandlerDefaultImpl.class ).in( Singleton.class );
68  // (given the "overriding" architecture, this is a default binding which may be overridden later)
69 
70  addQSimComponentBinding( COMPONENT_NAME ).to( NetworkModeDepartureHandler.class );
71  // (this will register the DepartureHandler functionality. Necessary since departureHandlers need to be registered. It will,
72  // however, use whatever is bound to the interface, and not necessarily the above binding.)
73 
74  // kai, jan'25:
75 
76  // I am currently thinking that the NetworkModeDepartureHandler as a separate interface is not needed. It used to be hardwired into
77  // the QNetsimEngine, but that is no longer the case. Technically, it just does something like
78  // qNetsimEngine.getNetsimNetwork.getNetsimLink.letVehicleDepart, so as long as all those classes have the necessary functionality, it
79  // does not have to be tightly integrated.
80 
81  // The question, in more general terms, is if we need to put things, which are registered as QSimComponents, also behind interfaces.
82 
83  // on the other hand, it may be a bit more natural (compared to the controler-related injection architecture) to replace the binding of
84  // the interface and rather not touch the QSimComponents if one does not have to.
85 
86  // The QSimComponent thing is really not much more than a multibinder, except that one can remove things before everything is plugged
87  // together. In other places, we say something like addTravelTimeBinding()( modeString ).to( ...Impl.class ). So there we are NOT putting
88  // an interface in between.
89 
90  }
91 }
final LinkedBindingBuilder< QSimComponent > addQSimComponentBinding(Annotation annotation)