orbit.client.net.ClientAuthInterceptor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of orbit-client Show documentation
Show all versions of orbit-client 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.client.net
import io.grpc.CallOptions
import io.grpc.Channel
import io.grpc.ClientCall
import io.grpc.ClientInterceptor
import io.grpc.ForwardingClientCall
import io.grpc.Metadata
import io.grpc.MethodDescriptor
import orbit.shared.proto.Headers
internal class ClientAuthInterceptor(private val localNode: LocalNode) : ClientInterceptor {
override fun interceptCall(
method: MethodDescriptor,
callOptions: CallOptions,
next: Channel
): ClientCall {
return object :
ForwardingClientCall.SimpleForwardingClientCall(next.newCall(method, callOptions)) {
override fun start(responseListener: Listener?, headers: Metadata) {
val nodeId = localNode.status.nodeInfo?.id
if (nodeId == null) {
headers.put(NAMESPACE, localNode.status.namespace)
} else {
headers.put(NAMESPACE, nodeId.namespace)
headers.put(NODE_KEY, nodeId.key)
}
super.start(responseListener, headers)
}
}
}
companion object {
private val NAMESPACE = Metadata.Key.of(Headers.NAMESPACE_NAME, Metadata.ASCII_STRING_MARSHALLER)
private val NODE_KEY = Metadata.Key.of(Headers.NODE_KEY_NAME, Metadata.ASCII_STRING_MARSHALLER)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy