Prevent multiple instances within the same JVM from trying to start aeron at the same time
This commit is contained in:
parent
3cac148db6
commit
5c854c4fab
|
@ -11,6 +11,8 @@ import io.aeron.Subscription
|
|||
import io.aeron.driver.MediaDriver
|
||||
import io.aeron.exceptions.DriverTimeoutException
|
||||
import kotlinx.atomicfu.atomic
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import mu.KLogger
|
||||
import mu.KotlinLogging
|
||||
import org.agrona.concurrent.BackoffIdleStrategy
|
||||
|
@ -54,6 +56,9 @@ class AeronDriver(
|
|||
// AERON_PUBLICATION_LINGER_TIMEOUT, 5s by default (this can also be set as a URI param)
|
||||
private const val AERON_PUBLICATION_LINGER_TIMEOUT = 5_000L // in MS
|
||||
|
||||
// prevents multiple instances, within the same JVM, from starting at the exact same time.
|
||||
private val startMutex = Mutex()
|
||||
|
||||
private fun setConfigDefaults(config: Configuration, logger: KLogger) {
|
||||
// explicitly don't set defaults if we already have the context defined!
|
||||
if (config.contextDefined) {
|
||||
|
@ -312,14 +317,13 @@ class AeronDriver(
|
|||
return context
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If the driver is not already running, this will start the driver
|
||||
*
|
||||
* @throws Exception if there is a problem starting the media driver
|
||||
*/
|
||||
@Synchronized
|
||||
fun start() {
|
||||
suspend fun start() {
|
||||
startMutex.withLock {
|
||||
if (closeRequested.value) {
|
||||
logger.debug("Resetting media driver context")
|
||||
|
||||
|
@ -332,6 +336,7 @@ class AeronDriver(
|
|||
|
||||
restart()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* if we did NOT close, then will restart the media driver + aeron. If we manually closed aeron, then we won't try to restart
|
||||
|
|
Loading…
Reference in New Issue
Block a user