All Downloads are FREE. Search and download functionalities are using the official Maven repository.

orbit.server.pipeline.step.PlacementStep.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0a19
Show newest version
/*
 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