Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session config #158

Merged
merged 7 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4
fhirCoreVersion=6.2.6-SNAPSHOT

junitVersion=5.7.1
mockk_version=1.10.2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package controller.validation

import model.ValidationResponse
import org.hl7.fhir.validation.cli.utils.VersionUtil
import org.hl7.fhir.utilities.VersionUtil
import org.hl7.fhir.validation.cli.model.ValidationRequest
import org.hl7.fhir.validation.cli.services.ValidationService
import org.koin.core.component.KoinComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package controller.validation

import java.util.concurrent.TimeUnit;

import org.hl7.fhir.validation.cli.services.ValidationService
import org.hl7.fhir.validation.cli.services.SessionCache

private const val MIN_FREE_MEMORY = 250000000
private const val SESSION_DEFAULT_DURATION: Long = 60

class ValidationServiceFactoryImpl : ValidationServiceFactory {
private val sessionCacheDuration: Long
private var sessionCache: SessionCache
private var validationService: ValidationService

private var validationService = ValidationService();

init {
sessionCacheDuration = System.getenv("SESSION_CACHE_DURATION")?.toLong() ?: SESSION_DEFAULT_DURATION;
sessionCache = SessionCache(sessionCacheDuration, TimeUnit.MINUTES);
sessionCache.setExpirationAfterAccess(true);
validationService = 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();
sessionCache = SessionCache(sessionCacheDuration, TimeUnit.MINUTES);
sessionCache.setExpirationAfterAccess(true);
validationService = ValidationService(sessionCache);
}
return validationService;
}
Expand Down
Loading