Skip to content

Commit

Permalink
Calculate seconds correctly in ConnectivityChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed May 3, 2024
1 parent f3fcf74 commit 5734d7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.github.oshai.kotlinlogging.KotlinLogging
import java.time.Clock
import java.time.Duration
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
Expand Down Expand Up @@ -75,16 +76,16 @@ class ConnectivityChecker(
get() {
val now = LocalDateTime.now(clock)
return when {
Duration.between(connectionState.lastEchoReceived, now).seconds < connectionAliveSeconds -> ALIVE.also {
ChronoUnit.SECONDS.between(connectionState.lastEchoReceived, now) < connectionAliveSeconds -> ALIVE.also {
logger.trace { "[$connectivityCheckable] Last echo within threshold, connection considered alive" }
}

Duration.between(connectionState.lastEchoRequested, now).seconds > connectionEchoPendingSeconds &&
ChronoUnit.SECONDS.between(connectionState.lastEchoRequested, now) > connectionEchoPendingSeconds &&
Duration.between(connectionState.lastEchoRequested, connectionState.lastEchoReceived).seconds < connectionEchoPendingSeconds -> ECHO_REQUIRED.also {
logger.trace { "[$connectivityCheckable] Echo waiting time within threshold, keep waiting" }
}

Duration.between(connectionState.lastEchoReceived, now).seconds < connectionDeadThresholdSeconds -> ECHO_PENDING.also {
ChronoUnit.SECONDS.between(connectionState.lastEchoReceived, now) < connectionDeadThresholdSeconds -> ECHO_PENDING.also {
logger.trace { "[$connectivityCheckable] No echo received (but still within 1 minute), connection critical" }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class AgentWrapper(
}
.getAsync { _ ->
val (agent, mediaStream) = synchronized(objectLock) {
checkNotNull(this.agent) to checkNotNull(this.mediaStream)
checkNotNull(this.agent) { "Agent must not be null" } to
checkNotNull(this.mediaStream) { "mediaStream must not be null" }
}

agent.createComponent(
Expand Down

0 comments on commit 5734d7c

Please sign in to comment.