Skip to content
Snippets Groups Projects
Commit 05b58b55 authored by William Walker's avatar William Walker
Browse files

wip

parent d5b0aa97
No related tags found
No related merge requests found
/*
* Designed and developed in 2022-2024 by William Walker (wnwalker@ucsc.edu)
* Copyright 2022-2024 The Regents of the University of California. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package edu.ucsc.its.temerity.di
import kotlinx.coroutines.CoroutineDispatcher
internal actual fun createLibraryDispatcher(): CoroutineDispatcher {
TODO("Not yet implemented")
}
...@@ -39,6 +39,7 @@ import kotlin.time.Duration ...@@ -39,6 +39,7 @@ import kotlin.time.Duration
* @property optWebTimeoutDuration Specifies the timeout [kotlin.time.Duration] to use when making web requests * @property optWebTimeoutDuration Specifies the timeout [kotlin.time.Duration] to use when making web requests
* @property optCacheTimeoutDuration Specifies the timeout [kotlin.time.Duration] to use when storing cache entries. Affects keep-alive time for cached instance data like user role type fields. * @property optCacheTimeoutDuration Specifies the timeout [kotlin.time.Duration] to use when storing cache entries. Affects keep-alive time for cached instance data like user role type fields.
* @property optThreadCount Specifies the number of threads to use for each client instance. Defaults to 2 at a minimum * @property optThreadCount Specifies the number of threads to use for each client instance. Defaults to 2 at a minimum
* @property optUseVirtualThreads Reserved for future use. Will configure library dispatchers to use virtual threads when available
* @property optEnableCompression Specifies whether to turn on compression for HTTP requests. Enabled by default. * @property optEnableCompression Specifies whether to turn on compression for HTTP requests. Enabled by default.
*/ */
@TemDsl @TemDsl
...@@ -62,6 +63,14 @@ public class TemClientConfig { ...@@ -62,6 +63,14 @@ public class TemClientConfig {
public var optThreadCount: Int? = null public var optThreadCount: Int? = null
/**
* [optUseVirtualThreads] Option flag to be used in future to switch to using Project Loom virtual thread-backed coroutine dispatchers
* Inop for now, as Android Gradle Plugin does not yet support compiling with JDK > 17
* Not to be converted to mutable field until JDK build target >= 21; required for Project Loom availability
* Treated as enum: null = unsupported by current library, false means disabled, true means enabled
*/
public val optUseVirtualThreads: Boolean? = null
public var optEnableCompression: Boolean = true public var optEnableCompression: Boolean = true
/** /**
......
...@@ -234,8 +234,25 @@ public class Temerity internal constructor( ...@@ -234,8 +234,25 @@ public class Temerity internal constructor(
"Service url must be provided. Set it using TemClientConfig.serviceUrl(url)" "Service url must be provided. Set it using TemClientConfig.serviceUrl(url)"
} }
libraryCoroutineDispatcher = get<CoroutineDispatcher>(named("libraryCoroutineDispatcher")) { libraryCoroutineDispatcher = when (config.optUseVirtualThreads) {
parametersOf(availableThreads(config.optThreadCount), "Temerity Library Dispatcher") // Case 1: User requests to enable virtual threads
// Need to check if JDK supports virtual threads
true -> {
val jvmVersion = Version.parse(BuildConfig.JVM_VERSION)
if (jvmVersion >= Version(21, 0, 0)) {
TODO("Configure virtual thread per task executor, create dispatcher")
} else {
get<CoroutineDispatcher>(named("libraryCoroutineDispatcher")) {
parametersOf(availableThreads(config.optThreadCount), "Temerity Library Dispatcher")
}
}
}
// Case 2: Virtual threads are identified as unsupported by null value as developer constant, or user requests to disable them: null | false
else -> {
get<CoroutineDispatcher>(named("libraryCoroutineDispatcher")) {
parametersOf(availableThreads(config.optThreadCount), "Temerity Library Dispatcher")
}
}
} }
libraryCoroutineScope = get<CoroutineScope>(named("libraryCoroutineScope")) { libraryCoroutineScope = get<CoroutineScope>(named("libraryCoroutineScope")) {
parametersOf(libraryCoroutineDispatcher) parametersOf(libraryCoroutineDispatcher)
......
/*
* Designed and developed in 2022-2024 by William Walker (wnwalker@ucsc.edu)
* Copyright 2022-2024 The Regents of the University of California. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package edu.ucsc.its.temerity.di
import kotlinx.coroutines.CoroutineDispatcher
internal expect fun createLibraryDispatcher(): CoroutineDispatcher
/*
* Designed and developed in 2022-2024 by William Walker (wnwalker@ucsc.edu)
* Copyright 2022-2024 The Regents of the University of California. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package edu.ucsc.its.temerity.di
import kotlinx.coroutines.CoroutineDispatcher
internal actual fun createLibraryDispatcher(): CoroutineDispatcher {
TODO("Not yet implemented")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment