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

com.twitter.finagle.netty4.channel.ServerBridge.scala Maven / Gradle / Ivy

There is a newer version: 24.2.0
Show newest version
package com.twitter.finagle.netty4.channel

import com.twitter.finagle.transport.{Transport, TransportContext}
import io.netty.channel.{Channel, ChannelHandlerContext, ChannelInboundHandlerAdapter}
import io.netty.channel.ChannelHandler.Sharable

/**
 * Bridges a `Channel` onto a [[Transport]].
 */
@Sharable
private[netty4] class ServerBridge[In, Out, Ctx <: TransportContext](
  transportFac: Channel => Transport[In, Out] { type Context <: Ctx },
  serveTransport: Transport[In, Out] { type Context <: Ctx } => Unit)
    extends ChannelInboundHandlerAdapter {

  override def channelActive(ctx: ChannelHandlerContext): Unit = {
    // We immediately eject ourselves from the pipeline as we don't have
    // any more value to provide.
    ctx.pipeline.remove(this)
    val transport = transportFac(ctx.channel())
    serveTransport(transport)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy