orbit.server.pipeline.step.PlacementStep.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.pipeline.step
import orbit.server.mesh.AddressableManager
import orbit.server.mesh.LocalNodeInfo
import orbit.server.pipeline.PipelineContext
import orbit.shared.net.InvocationReason
import orbit.shared.net.Message
import orbit.shared.net.MessageContent
import orbit.shared.net.MessageTarget
class PlacementStep(
private val addressableManager: AddressableManager,
private val localNodeInfo: LocalNodeInfo
) : PipelineStep {
override suspend fun onInbound(context: PipelineContext, msg: Message) {
when (val content = msg.content) {
is MessageContent.InvocationRequest -> {
val ineligibleNodes =
if (content.reason == InvocationReason.rerouted) listOf(context.metadata.authInfo.nodeId) else emptyList()
addressableManager.locateOrPlace(msg.source!!.namespace, content.destination, ineligibleNodes).also { location ->
msg.copy(
target = MessageTarget.Unicast(location)
).also { newMsg ->
context.next(newMsg)
}
}
}
is MessageContent.ConnectionInfoRequest ->
msg.source?.also { source ->
msg.copy(
target = MessageTarget.Unicast(source),
content = MessageContent.ConnectionInfoResponse(
nodeId = localNodeInfo.info.id
)
).also {
context.pushNew(it)
}
}
else -> context.next(msg)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy