Skip to content

Commit

Permalink
Session config (#158)
Browse files Browse the repository at this point in the history
* session expiration configurable

* create service function

* adding PassiveExpiringSessionCache

* Match renamed method

* Bump to current core SNAPSHOT

---------

Co-authored-by: dotasek <[email protected]>
  • Loading branch information
rpassas and dotasek committed Dec 18, 2023
1 parent a0bd5a6 commit 662990e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down

0 comments on commit 662990e

Please sign in to comment.