Made accessing JobCount thread safe
This commit is contained in:
parent
2563051082
commit
aa532b864c
|
@ -58,6 +58,8 @@ kotlin {
|
||||||
|
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.3.2"
|
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.3.2"
|
||||||
|
|
||||||
|
implementation "co.touchlab:stately-concurrency:1.2.0"
|
||||||
|
|
||||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
|
||||||
|
|
||||||
implementation "io.ktor:ktor-client-core:$ktorVersion"
|
implementation "io.ktor:ktor-client-core:$ktorVersion"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.dankito.banking.fints.model
|
package net.dankito.banking.fints.model
|
||||||
|
|
||||||
|
import co.touchlab.stately.concurrency.AtomicInt
|
||||||
import net.dankito.banking.fints.callback.FinTsClientCallback
|
import net.dankito.banking.fints.callback.FinTsClientCallback
|
||||||
import net.dankito.banking.fints.log.IMessageLogAppender
|
import net.dankito.banking.fints.log.IMessageLogAppender
|
||||||
import net.dankito.banking.fints.log.MessageContext
|
import net.dankito.banking.fints.log.MessageContext
|
||||||
|
@ -26,7 +27,7 @@ open class JobContext(
|
||||||
) : MessageBaseData(bank, product), IMessageLogAppender {
|
) : MessageBaseData(bank, product), IMessageLogAppender {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var JobCount = 0 // this is not thread safe so job number may not be 100 % accurate
|
private var JobCount = AtomicInt(0) // this variable is accessed from multiple threads, so make it thread safe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,14 +48,14 @@ open class JobContext(
|
||||||
get() = ArrayList(_dialogs) // create a copy
|
get() = ArrayList(_dialogs) // create a copy
|
||||||
|
|
||||||
|
|
||||||
protected open val jobNumber: Int = ++JobCount
|
protected open val jobNumber: Int = JobCount.incrementAndGet()
|
||||||
|
|
||||||
protected open var dialogNumber: Int = 0
|
protected open var dialogNumber: Int = 0
|
||||||
|
|
||||||
|
|
||||||
open fun startNewDialog(closeDialog: Boolean = true, dialogId: String = DialogContext.InitialDialogId,
|
open fun startNewDialog(closeDialog: Boolean = true, dialogId: String = DialogContext.InitialDialogId,
|
||||||
versionOfSecurityProcedure: VersionDesSicherheitsverfahrens = VersionDesSicherheitsverfahrens.Version_2,
|
versionOfSecurityProcedure: VersionDesSicherheitsverfahrens = VersionDesSicherheitsverfahrens.Version_2,
|
||||||
chunkedResponseHandler: ((BankResponse) -> Unit)? = dialog.chunkedResponseHandler) : DialogContext {
|
chunkedResponseHandler: ((BankResponse) -> Unit)? = dialog.chunkedResponseHandler) : DialogContext {
|
||||||
|
|
||||||
val newDialogContext = DialogContext(closeDialog, dialogId, chunkedResponseHandler)
|
val newDialogContext = DialogContext(closeDialog, dialogId, chunkedResponseHandler)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue