Skip to content

Commit

Permalink
fix: correctly log inside ObjectInstantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
hoelger committed Nov 6, 2024
1 parent 4d1ab24 commit 695fc1c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public ApplicationAmbassador(AmbassadorParameter ambassadorParameter) {
try {
SimulationKernel.SimulationKernel.setConfigurationPath(ambassadorParameter.configuration.getParentFile());
// try to read the configuration from the configuration file
ambassadorConfig = new ObjectInstantiation<>(CApplicationAmbassador.class).readFile(ambassadorParameter.configuration);
ambassadorConfig = new ObjectInstantiation<>(CApplicationAmbassador.class, log).readFile(ambassadorParameter.configuration);

Validate.isTrue(ambassadorConfig.eventSchedulerThreads > 0,
"Number of eventSchedulerThreads must be greater than zero."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void initialize(final long startTime, final long endTime) throws Internal
}

try {
CSns configuration = new ObjectInstantiation<>(CSns.class).readFile(ambassadorParameter.configuration);
CSns configuration = new ObjectInstantiation<>(CSns.class, log).readFile(ambassadorParameter.configuration);
if (configuration.singlehopDelay instanceof GammaSpeedDelay) {
log.info("Detected GammaSpeedDelay for. The SNS is currently ignoring speed of entities in its evaluation of delay values");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected AbstractNetworkAmbassador(AmbassadorParameter ambassadorParameter, Str
this.removedNodes = new ArrayList<>();

try {
config = new ObjectInstantiation<>(CAbstractNetworkAmbassador.class).readFile(ambassadorParameter.configuration);
config = new ObjectInstantiation<>(CAbstractNetworkAmbassador.class, log).readFile(ambassadorParameter.configuration);
} catch (InstantiationException e) {
log.warn("Problem when instantiating ambassador configuration from '{}'. Ignore file and try again with default config.", ambassadorParameter.configuration);
config = new CAbstractNetworkAmbassador();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected CHosts loadHostsConfiguration(Path hostConfigurationFile) {

private <T> T loadJsonConfiguration(Path configurationFile, Class<T> clazz) throws ExecutionException {
try (InputStream inputStream = loadResource(configurationFile)) {
return new ObjectInstantiation<>(clazz).read(inputStream);
return new ObjectInstantiation<>(clazz, getLogger()).read(inputStream);
} catch (IOException | InstantiationException e) {
printAndLog("Could not load file due to invalid format.", e);
throw new ExecutionException();
Expand All @@ -223,7 +223,7 @@ private <T> T loadJsonConfiguration(Path configurationFile, Class<T> clazz) thro
@SuppressWarnings("unchecked")
private <T> T loadJsonConfiguration(Path configurationFile, T defaultObject) {
try (InputStream inputStream = loadResource(configurationFile)) {
return new ObjectInstantiation<>((Class<T>) defaultObject.getClass()).read(inputStream);
return new ObjectInstantiation<>((Class<T>) defaultObject.getClass(), getLogger()).read(inputStream);
} catch (IOException | InstantiationException e) {
getLogger().warn("Could not load file {}. Using default configuration.", configurationFile);
return defaultObject;
Expand Down

0 comments on commit 695fc1c

Please sign in to comment.