orbit.server.mesh.local.LocalNodeDirectory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of orbit-server Show documentation
Show all versions of orbit-server Show documentation
Orbit is a system to make building highly scalable realtime services easier.
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project .
See license in LICENSE.
*/
package orbit.server.mesh.local
import orbit.server.mesh.NodeDirectory
import orbit.shared.mesh.NodeId
import orbit.shared.mesh.NodeInfo
import orbit.util.concurrent.HashMapBackedAsyncMap
import orbit.util.di.ExternallyConfigured
import orbit.util.time.Clock
import java.util.concurrent.ConcurrentHashMap
class LocalNodeDirectory(private val clock: Clock) :
HashMapBackedAsyncMap(),
NodeDirectory {
object LocalNodeDirectorySingleton : ExternallyConfigured {
override val instanceType = LocalNodeDirectory::class.java
}
override val map: ConcurrentHashMap
get() = globalMap
companion object {
@JvmStatic
private val globalMap = ConcurrentHashMap()
fun clear() {
globalMap.clear()
}
}
override suspend fun isHealthy(): Boolean {
return true
}
override suspend fun tick() {
// Cull expired
globalMap.values.filter { clock.inPast(it.lease.expiresAt) }.also { toDelete ->
toDelete.forEach {
remove(it.id)
}
}
}
override suspend fun entries(): Iterable> {
return globalMap.map { it.toPair() }
}
override suspend fun count() = globalMap.count().toLong()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy