From 662990e9f8cd9233c810d12784eddae18f1f5445 Mon Sep 17 00:00:00 2001 From: rpassas <35311744+rpassas@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:43:35 -0500 Subject: [PATCH] Session config (#158) * session expiration configurable * create service function * adding PassiveExpiringSessionCache * Match renamed method * Bump to current core SNAPSHOT --------- Co-authored-by: dotasek --- gradle.properties | 2 +- .../validation/ValidationServiceFactoryImpl.kt | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index aea8cbc5..0a2b0a3e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official kotlin.js.generate.executable.default=false # versions -fhirCoreVersion=6.2.6 +fhirCoreVersion=6.2.8-SNAPSHOT junitVersion=5.7.1 mockk_version=1.10.2 diff --git a/src/jvmMain/kotlin/controller/validation/ValidationServiceFactoryImpl.kt b/src/jvmMain/kotlin/controller/validation/ValidationServiceFactoryImpl.kt index af69dfcb..509ea0e6 100644 --- a/src/jvmMain/kotlin/controller/validation/ValidationServiceFactoryImpl.kt +++ b/src/jvmMain/kotlin/controller/validation/ValidationServiceFactoryImpl.kt @@ -1,19 +1,31 @@ package controller.validation +import java.util.concurrent.TimeUnit; import org.hl7.fhir.validation.cli.services.ValidationService +import org.hl7.fhir.validation.cli.services.SessionCache +import org.hl7.fhir.validation.cli.services.PassiveExpiringSessionCache private const val MIN_FREE_MEMORY = 250000000 +private const val SESSION_DEFAULT_DURATION: Long = 60 class ValidationServiceFactoryImpl : ValidationServiceFactory { + private var validationService: ValidationService - private var validationService = ValidationService(); + init { + validationService = createValidationServiceInstance(); + } + fun createValidationServiceInstance() : ValidationService { + val sessionCacheDuration = System.getenv("SESSION_CACHE_DURATION")?.toLong() ?: SESSION_DEFAULT_DURATION; + val sessionCache: SessionCache = PassiveExpiringSessionCache(sessionCacheDuration, TimeUnit.MINUTES).setResetExpirationAfterFetch(true); + return ValidationService(sessionCache); + } + override fun getValidationService() : ValidationService { - if (java.lang.Runtime.getRuntime().freeMemory() < MIN_FREE_MEMORY) { println("Free memory ${java.lang.Runtime.getRuntime().freeMemory()} is less than ${MIN_FREE_MEMORY}. Re-initializing validationService"); - validationService = ValidationService(); + validationService = createValidationServiceInstance(); } return validationService; }