Add default implementation to the provider.

This commit is contained in:
Alexander Nozik 2020-08-15 20:33:39 +03:00
parent b5b0a6898e
commit 617612bf67
5 changed files with 39 additions and 17 deletions

18
CHANGELOG.md Normal file
View File

@ -0,0 +1,18 @@
# Changelog
## [Unreleased]
### Added
### Changed
- Empty query in Name is null instead of ""
- Provider provides an empty map instead of error by default
### Deprecated
### Removed
- Functional server prototype
### Fixed
- Global context CoroutineScope resolution
### Security

View File

@ -4,9 +4,10 @@ plugins {
id("scientifik.jvm") version toolsVersion apply false
id("scientifik.publish") version toolsVersion apply false
id("org.jetbrains.dokka") version "0.10.1"
id("org.jetbrains.changelog") version "0.4.0"
}
val dataforgeVersion by extra("0.1.9-dev")
val dataforgeVersion by extra("0.1.9-dev-1")
val bintrayRepo by extra("dataforge")
val githubProject by extra("dataforge-core")

View File

@ -8,6 +8,7 @@ import hep.dataforge.provider.Provider
import hep.dataforge.provider.top
import hep.dataforge.values.Value
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import mu.KLogger
@ -92,7 +93,7 @@ open class Context(
config.action()
}
override val coroutineContext: CoroutineContext by lazy {
open override val coroutineContext: CoroutineContext by lazy {
(parent ?: Global).coroutineContext.let { parenContext ->
parenContext + SupervisorJob(parenContext[Job])
}
@ -130,6 +131,9 @@ inline fun <reified T : Any> Context.content(target: String): Map<Name, T> =
* A global root context. Closing [Global] terminates the framework.
*/
object Global : Context("GLOBAL".asName(), null) {
override val coroutineContext: CoroutineContext = GlobalScope.coroutineContext + SupervisorJob()
/**
* Closing all contexts
*

View File

@ -16,7 +16,6 @@
package hep.dataforge.provider
import hep.dataforge.names.Name
import hep.dataforge.names.toName
/**
* A marker utility interface for providers.
@ -64,16 +63,16 @@ fun Provider.provide(path: Path, targetOverride: String? = null): Any? {
/**
* Type checked provide
*/
inline fun <reified T : Any> Provider.provide(path: String): T? {
return provide(Path.parse(path)) as? T
inline fun <reified T : Any> Provider.provide(path: String, targetOverride: String? = null): T? {
return provide(Path.parse(path), targetOverride) as? T
}
inline fun <reified T : Any> Provider.provide(target: String, name: Name): T? {
return provide(PathToken(name, target).toPath()) as? T
}
inline fun <reified T : Any> Provider.provide(target: String, name: String): T? =
provide(target, name.toName())
//
//inline fun <reified T : Any> Provider.provide(target: String, name: Name): T? {
// return provide(PathToken(name, target).toPath()) as? T
//}
//
//inline fun <reified T : Any> Provider.provide(target: String, name: String): T? =
// provide(target, name.toName())
/**
* Typed top level content

View File

@ -26,11 +26,11 @@ inline fun <reified T : Any> Provider.provideByType(name: String): T? {
val target = Types[T::class]
return provide(target, name)
}
inline fun <reified T : Any> Provider.provideByType(name: Name): T? {
val target = Types[T::class]
return provide(target, name)
}
//
//inline fun <reified T : Any> Provider.provideByType(name: Name): T? {
// val target = Types[T::class]
// return provide(target, name)
//}
inline fun <reified T : Any> Provider.top(): Map<Name, T> {
val target = Types[T::class]