diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControlerUtilsIT.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java similarity index 99% rename from contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControlerUtilsIT.java rename to contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java index 19b550dda95..76738a411a9 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControlerUtilsIT.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java @@ -53,7 +53,7 @@ * @author kturner * */ -public class CarrierControlerUtilsIT { +public class CarrierControllerUtilsIT{ private final Id CARRIER_SERVICES_ID = Id.create("CarrierWServices", Carrier.class); private final Id CARRIER_SHIPMENTS_ID = Id.create("CarrierWShipments", Carrier.class); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControlerUtilsTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java similarity index 99% rename from contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControlerUtilsTest.java rename to contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java index a494355934c..87ac86ec9b3 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControlerUtilsTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java @@ -59,12 +59,12 @@ import java.net.URL; import java.util.Collection; -public class CarrierControlerUtilsTest { +public class CarrierControllerUtilsTest{ @RegisterExtension private MatsimTestUtils utils = new MatsimTestUtils(); - private static final Logger log = LogManager.getLogger(CarrierControlerUtilsTest.class); + private static final Logger log = LogManager.getLogger( CarrierControllerUtilsTest.class ); private final Id CARRIER_SERVICES_ID = Id.create("CarrierWServices", Carrier.class); private final Id CARRIER_SHIPMENTS_ID = Id.create("CarrierWShipments", Carrier.class); diff --git a/contribs/multimodal/src/main/java/org/matsim/contrib/multimodal/RunMultimodalExample.java b/contribs/multimodal/src/main/java/org/matsim/contrib/multimodal/RunMultimodalExample.java index 6f1d5b48b0c..879c3d9dca5 100644 --- a/contribs/multimodal/src/main/java/org/matsim/contrib/multimodal/RunMultimodalExample.java +++ b/contribs/multimodal/src/main/java/org/matsim/contrib/multimodal/RunMultimodalExample.java @@ -26,8 +26,6 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; -import org.matsim.core.controler.ControlerUtils; -import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.scenario.ScenarioUtils; /** diff --git a/matsim/src/main/java/org/matsim/core/controler/AbstractController.java b/matsim/src/main/java/org/matsim/core/controler/AbstractController.java index a1c008e31ba..6775c0fc998 100644 --- a/matsim/src/main/java/org/matsim/core/controler/AbstractController.java +++ b/matsim/src/main/java/org/matsim/core/controler/AbstractController.java @@ -79,7 +79,7 @@ protected final void run(final Config config) { public void run() throws MatsimRuntimeModifications.UnexpectedShutdownException { loadCoreListeners(); controlerListenerManagerImpl.fireControlerStartupEvent(); - ControlerUtils.checkConfigConsistencyAndWriteToLog(config, "config dump before iterations start"); + ControllerUtils.checkConfigConsistencyAndWriteToLog(config, "config dump before iterations start" ); prepareForSim(); doIterations(config); } diff --git a/matsim/src/main/java/org/matsim/core/controler/Controler.java b/matsim/src/main/java/org/matsim/core/controler/Controler.java index bc7fbdc47da..22279357ada 100755 --- a/matsim/src/main/java/org/matsim/core/controler/Controler.java +++ b/matsim/src/main/java/org/matsim/core/controler/Controler.java @@ -65,7 +65,7 @@ * * @author mrieser */ -public final class Controler implements ControlerI, MatsimServices, AllowsConfiguration{ +public final class Controler implements Controller, ControlerI, MatsimServices, AllowsConfiguration{ // yyyy Design thoughts: // * Seems to me that we should try to get everything here final. Flexibility is provided by the ability to set or add factories. If this is // not sufficient, people should use AbstractController. kai, jan'13 diff --git a/matsim/src/main/java/org/matsim/core/controler/ControlerUtils.java b/matsim/src/main/java/org/matsim/core/controler/ControlerUtils.java index 490076578e5..be978146879 100644 --- a/matsim/src/main/java/org/matsim/core/controler/ControlerUtils.java +++ b/matsim/src/main/java/org/matsim/core/controler/ControlerUtils.java @@ -1,103 +1,30 @@ -/* *********************************************************************** * - * project: org.matsim.* * - * * - * *********************************************************************** * - * * - * copyright : (C) 2008 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ package org.matsim.core.controler; -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.google.inject.Injector; import org.matsim.api.core.v01.Scenario; import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigWriter; -import org.matsim.core.controler.corelisteners.ControlerDefaultCoreListenersModule; -import org.matsim.core.scenario.ScenarioByInstanceModule; /** - * @author nagel - * + * @deprecated -- use class and methods with double l. */ -public final class ControlerUtils { - private static final Logger log = LogManager.getLogger( ControlerUtils.class ) ; +@Deprecated +public class ControlerUtils { + private ControlerUtils(){} // namespace only; do not instantiate + /** - * This is meant for creating the matsim injector if one does not need/want {@link Controler}. Technical reason is that {@link Controler} creates - * the injector in the run method, and then it is too late to extract material in a direct way. - * - * @param config * @param scenario * @return + * @deprecated -- use controller methods with double l */ - public static com.google.inject.Injector createAdhocInjector( Config config, Scenario scenario ){ - return Injector.createInjector( config, new AbstractModule(){ - @Override public void install(){ - install( new NewControlerModule() ); - install( new ControlerDefaultCoreListenersModule() ); - install( new ControlerDefaultsModule() ); - install( new ScenarioByInstanceModule( scenario ) ); - } - } ); - } - - private ControlerUtils() {} // namespace for static methods only should not be instantiated - - /** - * Design decisions: - *
    - *
  • I extracted this method since it is now called twice: once - * directly after reading, and once before the iterations start. The second - * call seems more important, but I wanted to leave the first one there in - * case the program fails before that config dump. Might be put into the - * "unexpected shutdown hook" instead. kai, dec'10 - * - * Removed the first call for now, because I am now also checking for - * consistency with loaded controler modules. If still desired, we can - * put it in the shutdown hook.. michaz aug'14 - * - *
- * - * @param config TODO - * @param message the message that is written just before the config dump - */ - public static final void checkConfigConsistencyAndWriteToLog(Config config, - final String message) { - log.info(message); - String newline = System.lineSeparator();// use native line endings for logfile - StringWriter writer = new StringWriter(); - new ConfigWriter(config).writeStream(new PrintWriter(writer), newline); - log.info(newline + newline + writer.getBuffer().toString()); - log.info("Complete config dump done."); - log.info("Checking consistency of config..."); - config.checkConsistency(); - log.info("Checking consistency of config done."); - } - - @Deprecated // use OutputDirectoryLogging.catchLogEntries() directly. kai, mar'18 - public static final void initializeOutputLogging() { - OutputDirectoryLogging.catchLogEntries(); + @Deprecated + public Controler createControler( Scenario scenario ) { + return (Controler) ControllerUtils.createController( scenario ); } - public static void catchLogEntries() { - OutputDirectoryLogging.catchLogEntries(); + public Injector createAdhocInjector( Config config, Scenario scenario ) { + return ControllerUtils.createAdhocInjector( config, scenario ); } - - public Controler createControler( Scenario scenario ) { - return new Controler( scenario ); + public Injector createAdhocInjector( Scenario scenario ) { + return ControllerUtils.createAdhocInjector( scenario ); } - } diff --git a/matsim/src/main/java/org/matsim/core/controler/Controller.java b/matsim/src/main/java/org/matsim/core/controler/Controller.java new file mode 100644 index 00000000000..17dc747424f --- /dev/null +++ b/matsim/src/main/java/org/matsim/core/controler/Controller.java @@ -0,0 +1,7 @@ +package org.matsim.core.controler; + +/** + * This is an attempt to allow a syntax that spells controller with double l. + */ +public interface Controller extends MatsimServices, AllowsConfiguration, Runnable { +} diff --git a/matsim/src/main/java/org/matsim/core/controler/ControllerUtils.java b/matsim/src/main/java/org/matsim/core/controler/ControllerUtils.java new file mode 100644 index 00000000000..05665604a40 --- /dev/null +++ b/matsim/src/main/java/org/matsim/core/controler/ControllerUtils.java @@ -0,0 +1,121 @@ +/* *********************************************************************** * + * project: org.matsim.* * + * * + * *********************************************************************** * + * * + * copyright : (C) 2008 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ +package org.matsim.core.controler; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.matsim.api.core.v01.Scenario; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigWriter; +import org.matsim.core.controler.corelisteners.ControlerDefaultCoreListenersModule; +import org.matsim.core.scenario.ScenarioByInstanceModule; + +/** + * @author nagel + * + */ +public final class ControllerUtils{ + private static final Logger log = LogManager.getLogger( ControllerUtils.class ) ; + /** + * This is meant for creating the matsim injector if one does not need/want {@link Controler}. Technical reason is that {@link Controler} creates + * the injector in the run method, and then it is too late to extract material in a direct way. + * + * @param config + * @param scenario + * @return + */ + public static com.google.inject.Injector createAdhocInjector( Config config, Scenario scenario ){ + return Injector.createInjector( config, new AbstractModule(){ + @Override public void install(){ + install( new NewControlerModule() ); + install( new ControlerDefaultCoreListenersModule() ); + install( new ControlerDefaultsModule() ); + install( new ScenarioByInstanceModule( scenario ) ); + } + } ); + } + /** + * This is meant for creating the matsim injector if one does not need/want {@link Controler}. + * Technical reason is that {@link Controler} creates + * the injector in the run method, and then it is too late to extract material in a direct way. + * + * @param scenario + * @return + */ + public static com.google.inject.Injector createAdhocInjector( Scenario scenario ){ + return Injector.createInjector( scenario.getConfig(), new AbstractModule(){ + @Override public void install(){ + install( new NewControlerModule() ); + install( new ControlerDefaultCoreListenersModule() ); + install( new ControlerDefaultsModule() ); + install( new ScenarioByInstanceModule( scenario ) ); + } + } ); + } + + private ControllerUtils() {} // namespace for static methods only should not be instantiated + + /** + * Design decisions: + *
    + *
  • I extracted this method since it is now called twice: once + * directly after reading, and once before the iterations start. The second + * call seems more important, but I wanted to leave the first one there in + * case the program fails before that config dump. Might be put into the + * "unexpected shutdown hook" instead. kai, dec'10 + * + * Removed the first call for now, because I am now also checking for + * consistency with loaded controler modules. If still desired, we can + * put it in the shutdown hook.. michaz aug'14 + * + *
+ * + * @param config TODO + * @param message the message that is written just before the config dump + */ + public static final void checkConfigConsistencyAndWriteToLog(Config config, + final String message) { + log.info(message); + String newline = System.lineSeparator();// use native line endings for logfile + StringWriter writer = new StringWriter(); + new ConfigWriter(config).writeStream(new PrintWriter(writer), newline); + log.info(newline + newline + writer.getBuffer().toString()); + log.info("Complete config dump done."); + log.info("Checking consistency of config..."); + config.checkConsistency(); + log.info("Checking consistency of config done."); + } + + @Deprecated // use OutputDirectoryLogging.catchLogEntries() directly. kai, mar'18 + public static final void initializeOutputLogging() { + OutputDirectoryLogging.catchLogEntries(); + } + + public static void catchLogEntries() { + OutputDirectoryLogging.catchLogEntries(); + } + + public static Controller createController( Scenario scenario ) { + return new Controler( scenario ); + } + +}