From 47b63173ac53fe91ef07f4d75e18cbfadf3adac0 Mon Sep 17 00:00:00 2001 From: Robinson Date: Thu, 29 Apr 2021 10:02:59 +0200 Subject: [PATCH] Added `cloneToNormal`, which converts the coroutine strategy -> thread strategy --- src/dorkbox/network/Client.kt | 4 ++-- .../network/aeron/CoroutineBackoffIdleStrategy.kt | 11 +++++++++-- src/dorkbox/network/aeron/CoroutineIdleStrategy.kt | 7 +++++++ .../aeron/CoroutineSleepingMillisIdleStrategy.kt | 8 ++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/dorkbox/network/Client.kt b/src/dorkbox/network/Client.kt index 4f4e396f..c060b6b5 100644 --- a/src/dorkbox/network/Client.kt +++ b/src/dorkbox/network/Client.kt @@ -621,10 +621,10 @@ open class Client(config: Configuration = Configuration * Removes the specified host address from the list of registered server keys. */ fun removeRegisteredServerKey(address: InetAddress) { - val savedPublicKey = settingsStore.getRegisteredServerKey(address) + val savedPublicKey = storage.getRegisteredServerKey(address) if (savedPublicKey != null) { logger.debug { "Deleting remote IP address key $address" } - settingsStore.removeRegisteredServerKey(address) + storage.removeRegisteredServerKey(address) } } diff --git a/src/dorkbox/network/aeron/CoroutineBackoffIdleStrategy.kt b/src/dorkbox/network/aeron/CoroutineBackoffIdleStrategy.kt index 40d575a7..3f8875d2 100644 --- a/src/dorkbox/network/aeron/CoroutineBackoffIdleStrategy.kt +++ b/src/dorkbox/network/aeron/CoroutineBackoffIdleStrategy.kt @@ -17,6 +17,7 @@ package dorkbox.network.aeron import kotlinx.coroutines.delay import kotlinx.coroutines.yield +import org.agrona.concurrent.BackoffIdleStrategy import org.agrona.hints.ThreadHints abstract class BackoffIdleStrategyPrePad { @@ -214,8 +215,7 @@ class CoroutineBackoffIdleStrategy : BackoffIdleStrategyData, CoroutineIdleStrat * @param minParkPeriodMs to use when initiating parking * @param maxParkPeriodMs to use for end duration when parking */ - constructor( - maxSpins: Long, maxYields: Long, minParkPeriodMs: Long, maxParkPeriodMs: Long) + constructor(maxSpins: Long, maxYields: Long, minParkPeriodMs: Long, maxParkPeriodMs: Long) : super(maxSpins, maxYields, minParkPeriodMs, maxParkPeriodMs) { } @@ -333,6 +333,13 @@ class CoroutineBackoffIdleStrategy : BackoffIdleStrategyData, CoroutineIdleStrat return CoroutineBackoffIdleStrategy(maxSpins = maxSpins, maxYields = maxYields, minParkPeriodMs = minParkPeriodMs, maxParkPeriodMs = maxParkPeriodMs) } + /** + * Creates a clone of this IdleStrategy + */ + override fun cloneToNormal(): BackoffIdleStrategy { + return BackoffIdleStrategy(maxSpins, maxYields, minParkPeriodMs, maxParkPeriodMs) + } + override fun toString(): String { return "BackoffIdleStrategy{" + "alias=" + ALIAS + diff --git a/src/dorkbox/network/aeron/CoroutineIdleStrategy.kt b/src/dorkbox/network/aeron/CoroutineIdleStrategy.kt index fd4c08cb..44ba436e 100644 --- a/src/dorkbox/network/aeron/CoroutineIdleStrategy.kt +++ b/src/dorkbox/network/aeron/CoroutineIdleStrategy.kt @@ -15,6 +15,8 @@ */ package dorkbox.network.aeron +import org.agrona.concurrent.IdleStrategy + /** * Idle strategy for use by threads when they do not have work to do. * @@ -107,4 +109,9 @@ interface CoroutineIdleStrategy { * Creates a clone of this IdleStrategy */ fun clone(): CoroutineIdleStrategy + + /** + * Creates a clone of this IdleStrategy + */ + fun cloneToNormal(): IdleStrategy } diff --git a/src/dorkbox/network/aeron/CoroutineSleepingMillisIdleStrategy.kt b/src/dorkbox/network/aeron/CoroutineSleepingMillisIdleStrategy.kt index e80b6967..c62345a1 100644 --- a/src/dorkbox/network/aeron/CoroutineSleepingMillisIdleStrategy.kt +++ b/src/dorkbox/network/aeron/CoroutineSleepingMillisIdleStrategy.kt @@ -16,6 +16,7 @@ package dorkbox.network.aeron import kotlinx.coroutines.delay +import org.agrona.concurrent.SleepingMillisIdleStrategy /** * When idle this strategy is to sleep for a specified period time in milliseconds. @@ -90,6 +91,13 @@ class CoroutineSleepingMillisIdleStrategy : CoroutineIdleStrategy { return CoroutineSleepingMillisIdleStrategy(sleepPeriodMs = sleepPeriodMs) } + /** + * Creates a clone of this IdleStrategy + */ + override fun cloneToNormal(): SleepingMillisIdleStrategy { + return SleepingMillisIdleStrategy(sleepPeriodMs) + } + override fun toString(): String { return "SleepingMillisIdleStrategy{" +