Skip to content

Commit 0d035d5

Browse files
committed
chore: replace local variable declarations with var
1 parent 2d4645b commit 0d035d5

1 file changed

Lines changed: 56 additions & 56 deletions

File tree

model/worker/src/main/java/ai/timefold/solver/model/worker/impl/SolverWorker.java

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ public SolverWorker(@ConfigProperty(name = "timefold.application.name") Optional
228228

229229
private void reportExecutionEnvironmentInfo() {
230230

231-
String nodeName = System.getenv(EnvironmentVars.K8S_INFO_NODE_NAME);
232-
String memoryLimit = System.getenv(EnvironmentVars.K8S_INFO_MEMORY_LIMIT);
233-
String totalMemory = String.valueOf(Runtime.getRuntime().maxMemory());
231+
var nodeName = System.getenv(EnvironmentVars.K8S_INFO_NODE_NAME);
232+
var memoryLimit = System.getenv(EnvironmentVars.K8S_INFO_MEMORY_LIMIT);
233+
var totalMemory = String.valueOf(Runtime.getRuntime().maxMemory());
234234

235-
String java = System.getProperty("java.version");
236-
String osArch = System.getProperty("os.arch");
237-
String os = System.getProperty("os.name");
238-
String cores = String.valueOf(Runtime.getRuntime().availableProcessors());
235+
var java = System.getProperty("java.version");
236+
var osArch = System.getProperty("os.arch");
237+
var os = System.getProperty("os.name");
238+
var cores = String.valueOf(Runtime.getRuntime().availableProcessors());
239239

240240
if (modelName.isPresent() && modelVersion.isPresent() && applicationVersion.isPresent()) {
241241
LOGGER.info("Model {} {} ({})", modelName.get(), modelVersion.get(), applicationVersion.get());
@@ -265,8 +265,8 @@ private void sendEvent(Emitter emitter, AbstractEvent event) {
265265
*/
266266
public void onStart(@Observes StartupEvent event) {
267267
reportExecutionEnvironmentInfo();
268-
String id = System.getenv(EnvironmentVars.ENV_TIMEFOLD_JOB_ID);
269-
String onStartCommandEnv = System.getenv(EnvironmentVars.ENV_TIMEFOLD_ON_START_COMMAND);
268+
var id = System.getenv(EnvironmentVars.ENV_TIMEFOLD_JOB_ID);
269+
var onStartCommandEnv = System.getenv(EnvironmentVars.ENV_TIMEFOLD_ON_START_COMMAND);
270270
if (id == null && onStartCommandEnv == null) {
271271
LOGGER.atDebug().log("No environment variables specified; assuming the solver worked is running locally.");
272272
return;
@@ -281,7 +281,7 @@ public void onStart(@Observes StartupEvent event) {
281281
true);
282282
}
283283

284-
OnStartCommand onStartCommand = OnStartCommand.valueOf(onStartCommandEnv);
284+
var onStartCommand = OnStartCommand.valueOf(onStartCommandEnv);
285285

286286
if (onStartCommand == OnStartCommand.IDLE) {
287287
startIdle();
@@ -294,7 +294,7 @@ public void onStart(@Observes StartupEvent event) {
294294
true);
295295
}
296296

297-
Metadata metadata = storageService.getMetadata(id);
297+
var metadata = storageService.getMetadata(id);
298298
// if the dataset is in any of the final states, return/shutdown immediately
299299
if (metadata.getSolverStatus() == SolvingStatus.DATASET_INVALID
300300
|| metadata.getSolverStatus() == SolvingStatus.SOLVING_FAILED
@@ -331,8 +331,8 @@ public void onStart(@Observes StartupEvent event) {
331331
* {@link EnvironmentVars#ENV_TIMEFOLD_IDLE_RUNTIME_TTL}.
332332
*/
333333
private void startIdle() {
334-
Duration shutdownDelay = Duration.ofMinutes(10);
335-
String delayDurationEnv = System.getenv(EnvironmentVars.ENV_TIMEFOLD_IDLE_RUNTIME_TTL);
334+
var shutdownDelay = Duration.ofMinutes(10);
335+
var delayDurationEnv = System.getenv(EnvironmentVars.ENV_TIMEFOLD_IDLE_RUNTIME_TTL);
336336
if (delayDurationEnv != null) {
337337
shutdownDelay = Duration.parse(delayDurationEnv);
338338
}
@@ -342,22 +342,22 @@ private void startIdle() {
342342
private void computeOutputs(String id) {
343343
LOGGER.info("Requesting solver for id {} to compute outputs...", id);
344344
try {
345-
Metadata metadata = storageService.getMetadata(id);
346-
ModelInput modelInput = storageService.getModelInput(id);
345+
var metadata = storageService.getMetadata(id);
346+
var modelInput = storageService.getModelInput(id);
347347
if (modelInput == null) {
348348
logUnreadableInput(id);
349349
return;
350350
}
351-
Configuration configuration = storageService.getConfiguration(id);
351+
var configuration = storageService.getConfiguration(id);
352352

353-
ModelConfig modelConfig = Configuration.getSafeModelConfig(configuration);
353+
var modelConfig = Configuration.getSafeModelConfig(configuration);
354354

355-
SolverModel solverModel = createSolverModel(modelInput, modelConfig);
355+
var solverModel = createSolverModel(modelInput, modelConfig);
356356
applyResolvedMapLocation(metadata);
357357
solutionManager.update(solverModel);
358358

359359
// Store the updated solution
360-
ModelOutput modelOutput = convertToModelOutput(id, solverModel);
360+
var modelOutput = convertToModelOutput(id, solverModel);
361361
metadata.datasetComputed();
362362
storageService.storeSolution(id, modelOutput, metadata, extractInputMetrics(solverModel),
363363
extractOutputMetrics(solverModel));
@@ -406,19 +406,19 @@ private void startSolvingOnApplicationStart(String id) {
406406
* @param configuration the configuration to use; can be null
407407
*/
408408
private void solve(Metadata metadata, ModelInput modelInput, Configuration configuration) {
409-
final String id = metadata.getId();
409+
final var id = metadata.getId();
410410
LOGGER.info("Requesting solver for id {} to start...", id);
411411
try {
412-
TerminationConfig terminationConfig =
412+
var terminationConfig =
413413
terminationService.resolveTerminationConfig(
414414
(configuration == null || configuration.run() == null) ? null : configuration.run().termination());
415-
SolverConfigOverride solverConfigOverride = new SolverConfigOverride()
415+
var solverConfigOverride = new SolverConfigOverride()
416416
.withTerminationConfig(terminationConfig);
417417

418-
ModelConfig modelConfig = Configuration.getSafeModelConfig(configuration);
418+
var modelConfig = Configuration.getSafeModelConfig(configuration);
419419

420420
var previousModelOutput = loadModelOutput(id);
421-
SolverJob<SolverModel> job = solverManager.solveBuilder()
421+
var job = solverManager.solveBuilder()
422422
.withProblemFinder(id_ -> notifyOnStart((String) id_, modelInput, previousModelOutput, modelConfig))
423423
.withConfigOverride(solverConfigOverride)
424424
.withProblemId(id)
@@ -436,7 +436,7 @@ private void solve(Metadata metadata, ModelInput modelInput, Configuration confi
436436
}
437437

438438
private LegacyValidationResult validateAndUpdateRun(String id) {
439-
Metadata metadata = storageService.getMetadata(id);
439+
var metadata = storageService.getMetadata(id);
440440

441441
if (metadata.getSolverStatus() == SolvingStatus.DATASET_VALIDATED
442442
|| metadata.getSolverStatus() == SolvingStatus.SOLVING_ACTIVE
@@ -445,7 +445,7 @@ private LegacyValidationResult validateAndUpdateRun(String id) {
445445
return LegacyValidationResult.successful();
446446
}
447447

448-
ModelInput modelInput = storageService.getModelInput(id);
448+
var modelInput = storageService.getModelInput(id);
449449
if (modelInput == null) {
450450
logUnreadableInput(id);
451451
/*
@@ -456,14 +456,14 @@ private LegacyValidationResult validateAndUpdateRun(String id) {
456456
}
457457

458458
var modelConfig = Configuration.getSafeModelConfig(storageService.getConfiguration(id));
459-
ValidationBuilder validationBuilder = new ValidationBuilder();
459+
var validationBuilder = new ValidationBuilder();
460460
modelValidator.validate(validationBuilder, modelInput, modelConfig);
461461

462462
// We store both the new and old validation result format for backward compatibility.
463463
ValidationResult validationResponse = validationBuilder.build();
464464
storageService.storeValidationResponse(id, validationResponse);
465465

466-
LegacyValidationResult legacyValidationResult = validationBuilder.buildLegacyValidationResult();
466+
var legacyValidationResult = validationBuilder.buildLegacyValidationResult();
467467
metadata.datasetValidated(legacyValidationResult);
468468
storageService.updateMetadata(metadata.getId(), metadata);
469469

@@ -473,7 +473,7 @@ private LegacyValidationResult validateAndUpdateRun(String id) {
473473

474474
public void onShutdown(@Observes ShutdownEvent event) {
475475
this.shuttingDown.set(true);
476-
String id = System.getenv(EnvironmentVars.ENV_TIMEFOLD_JOB_ID);
476+
var id = System.getenv(EnvironmentVars.ENV_TIMEFOLD_JOB_ID);
477477
if (id != null) {
478478

479479
try {
@@ -488,7 +488,7 @@ public void onShutdown(@Observes ShutdownEvent event) {
488488
@Blocking
489489
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
490490
public void onDatasetValidateComputeCommand(DatasetValidateComputeCommand command) {
491-
final String id = command.getId();
491+
final var id = command.getId();
492492
try {
493493
if (!validateAndUpdateRun(id).isValid()) {
494494
LOGGER.error("Dataset (%s) failed validation. Please check the validation results.".formatted(id));
@@ -510,14 +510,14 @@ public void onDatasetValidateComputeCommand(DatasetValidateComputeCommand comman
510510
@Blocking
511511
@Acknowledgment(Acknowledgment.Strategy.PRE_PROCESSING)
512512
public void onSolveStartCommand(SolveStartCommand command) {
513-
final String id = command.getId();
514-
Metadata metadata = storageService.getMetadata(id);
515-
ModelInput modelInput = storageService.getModelInput(id);
513+
final var id = command.getId();
514+
var metadata = storageService.getMetadata(id);
515+
var modelInput = storageService.getModelInput(id);
516516
if (modelInput == null) {
517517
logUnreadableInput(id);
518518
return;
519519
}
520-
Configuration configuration = storageService.getConfiguration(id);
520+
var configuration = storageService.getConfiguration(id);
521521

522522
processor.onNext(metadata);
523523

@@ -533,7 +533,7 @@ public void onSolveTerminateCommand(SolveTerminateCommand command) {
533533
return;
534534
}
535535

536-
String id = command.getId();
536+
var id = command.getId();
537537
LOGGER.info("Request to terminate solver has been received for id {}", id);
538538
if (!solverManager.getSolverStatus(id).equals(SolverStatus.NOT_SOLVING)) {
539539
completionStatus.initiateCompletion(id);
@@ -566,9 +566,9 @@ public Multi<Metadata<?>> forwardLifeCycleEvent() {
566566
protected SolverModel notifyOnStart(String id, ModelInput modelInput, ModelOutput modelOutput, ModelConfig modelConfig) {
567567
try {
568568
LOGGER.debug("Notify run start for id {}", id);
569-
Metadata metadata = storageService.getMetadata(id);
569+
var metadata = storageService.getMetadata(id);
570570

571-
SolverModel solverModel = createSolverModel(modelInput, modelConfig, modelOutput);
571+
var solverModel = createSolverModel(modelInput, modelConfig, modelOutput);
572572
applyResolvedMapLocation(metadata);
573573
if (metadata.getSolverStatus() == SolvingStatus.DATASET_COMPUTED
574574
|| metadata.getSolverStatus() == SolvingStatus.SOLVING_SCHEDULED) {
@@ -597,7 +597,7 @@ protected SolverModel notifyOnStart(String id, ModelInput modelInput, ModelOutpu
597597

598598
private SolverModel createSolverModel(ModelInput modelInput, ModelConfig modelConfig, ModelOutput modelOutput) {
599599
try {
600-
SolverModel solverModel =
600+
var solverModel =
601601
modelConvertor.toSolverModel(modelInput, modelConfig, Optional.ofNullable(modelOutput));
602602
return enrichModel(solverModel);
603603
} catch (TimefoldRuntimeException e) {
@@ -620,12 +620,12 @@ private SolverModel enrichModel(SolverModel solverModel) {
620620
}
621621

622622
private void applyResolvedMapLocation(Metadata metadata) {
623-
String resolved = mapEnrichmentContext.getResolvedMapLocation();
623+
var resolved = mapEnrichmentContext.getResolvedMapLocation();
624624
if (resolved == null || metadata == null) {
625625
return;
626626
}
627627
metadata.setResolvedMapLocation(resolved);
628-
String configuredLocation = System.getenv(EnvironmentVars.ENV_TIMEFOLD_PLATFORM_MAP_SERVICE_LOCATION);
628+
var configuredLocation = System.getenv(EnvironmentVars.ENV_TIMEFOLD_PLATFORM_MAP_SERVICE_LOCATION);
629629
if (EnvironmentVars.MAP_SERVICE_LOCATION_AUTO_SELECT.equalsIgnoreCase(configuredLocation)) {
630630
LOGGER.info("Auto-select map resolved to '{}' for dataset {}.", resolved, metadata.getId());
631631
}
@@ -638,10 +638,10 @@ protected void notifyOnInit(String id, SolverModel solverModel, boolean isTermin
638638
LOGGER.warn("Initial solution for id {} incomplete because terminated early", id);
639639
}
640640

641-
Metadata metadata = storageService.getMetadata(id);
642-
SolverJob<SolverModel> solverJob = solverJobs.get(id);
641+
var metadata = storageService.getMetadata(id);
642+
var solverJob = solverJobs.get(id);
643643
if (metadata != null && SolvingStatus.SOLVING_ACTIVE == metadata.getSolverStatus() && solverJob != null) {
644-
ModelOutput modelOutput = convertToModelOutput(id, solverModel);
644+
var modelOutput = convertToModelOutput(id, solverModel);
645645

646646
metadata.updateStatusOnSave(SolvingStatus.SOLVING_ACTIVE, solverModel.getScore());
647647
storageService.updateSolution(id, modelOutput, metadata, extractInputMetrics(solverModel),
@@ -654,11 +654,11 @@ protected void notifyOnInit(String id, SolverModel solverModel, boolean isTermin
654654

655655
protected void notifyOnSave(String id, SolverModel solverModel, EventProducerId eventProducerId) {
656656
LOGGER.debug("Notify run save for id {}", id);
657-
Metadata metadata = storageService.getMetadata(id);
658-
SolverJob<SolverModel> solverJob = solverJobs.get(id);
657+
var metadata = storageService.getMetadata(id);
658+
var solverJob = solverJobs.get(id);
659659
if (metadata != null && SolvingStatus.SOLVING_ACTIVE == metadata.getSolverStatus() && solverJob != null) {
660660
processor.onNext(metadata);
661-
ModelOutput modelOutput = convertToModelOutput(id, solverModel);
661+
var modelOutput = convertToModelOutput(id, solverModel);
662662

663663
metadata.updateStatusOnSave(SolvingStatus.SOLVING_ACTIVE, solverModel.getScore());
664664
storageService.updateSolution(id, modelOutput, metadata, extractInputMetrics(solverModel),
@@ -680,15 +680,15 @@ protected void notifyOnComplete(String id, SolverModel solverModel) {
680680
LOGGER.debug("Notify run complete for id {}", id);
681681
try {
682682
// remove it as the first thing so in case any best solution events will arrive while this method is executed they will be discarded
683-
SolverJob<SolverModel> solverJob = solverJobs.remove(id);
683+
var solverJob = solverJobs.remove(id);
684684

685685
if (solverJob == null) {
686686
return;
687687
}
688-
ModelOutput modelOutput = convertToModelOutput(id, solverModel);
688+
var modelOutput = convertToModelOutput(id, solverModel);
689689
storeSolvedInput(id, modelOutput);
690690

691-
Metadata metadata = storageService.getMetadata(id);
691+
var metadata = storageService.getMetadata(id);
692692
if (metadata.getScore() == null) {
693693
// If the score is null, a full solution was not found and the CH did not finish
694694
metadata.updateStatusOnComplete(SolvingStatus.SOLVING_INCOMPLETE, solverModel.getScore());
@@ -719,7 +719,7 @@ protected void notifyOnComplete(String id, SolverModel solverModel) {
719719
* Invokes post processors of the solution to compute additional (optional) outputs, like score analysis or waypoints.
720720
*/
721721
private void postProcessOutput(String id, ModelOutput modelOutput, SolverModel solverModel) {
722-
for (ModelPostProcessor processor : modelPostProcessors) {
722+
for (var processor : modelPostProcessors) {
723723
try {
724724
processor.processComputed(modelOutput, solverModel, id);
725725
} catch (Throwable e) {
@@ -730,7 +730,7 @@ private void postProcessOutput(String id, ModelOutput modelOutput, SolverModel s
730730
}
731731

732732
private void postProcessCompleteOutput(String id, ModelOutput modelOutput, SolverModel solverModel) {
733-
for (ModelPostProcessor processor : modelPostProcessors) {
733+
for (var processor : modelPostProcessors) {
734734
try {
735735
processor.process(modelOutput, solverModel, id);
736736
} catch (Throwable e) {
@@ -741,21 +741,21 @@ private void postProcessCompleteOutput(String id, ModelOutput modelOutput, Solve
741741
}
742742

743743
private void storeSolvedInput(String datasetId, ModelOutput modelOutput) {
744-
ModelInput modelInput = storageService.getModelInput(datasetId);
744+
var modelInput = storageService.getModelInput(datasetId);
745745
if (modelInput == null) {
746746
throw new ItemNotFoundException(datasetId, "Model input not found for id %s".formatted(datasetId));
747747
}
748-
ModelInput solvedModelInput = modelConvertor.applyOutputToInput(modelInput, modelOutput);
748+
var solvedModelInput = modelConvertor.applyOutputToInput(modelInput, modelOutput);
749749
storageService.storeSolvedModelInput(datasetId, solvedModelInput);
750750
}
751751

752752
public void notifyOnFailure(Object id, Throwable throwable) {
753753
LOGGER.debug("Notify run failure for id {}", id, throwable);
754-
String problemId = (String) id;
754+
var problemId = (String) id;
755755
Metadata metadata = null;
756756
try {
757757
// remove it as the first thing so in case any best solution events will arrive while this method is executed they will be discarded
758-
SolverJob<SolverModel> solverJob = solverJobs.remove(id);
758+
var solverJob = solverJobs.remove(id);
759759

760760
// update run status only as failed
761761
metadata = storageService.getMetadata(problemId);
@@ -768,7 +768,7 @@ public void notifyOnFailure(Object id, Throwable throwable) {
768768
}
769769
} finally {
770770

771-
for (ModelPostProcessor processor : modelPostProcessors) {
771+
for (var processor : modelPostProcessors) {
772772
try {
773773
processor.processFailed(problemId, throwable);
774774
} catch (Throwable e) {

0 commit comments

Comments
 (0)