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

com.twitter.finagle.mux.pushsession.PipelineInit.scala Maven / Gradle / Ivy

There is a newer version: 24.2.0
Show newest version
package com.twitter.finagle.mux.pushsession

import com.twitter.finagle.mux.transport.Netty4Framer
import com.twitter.finagle.netty4.CopyingByteReaderDecoder
import com.twitter.finagle.netty4.codec.BufCodec
import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel._

private[finagle] object PipelineInit extends Netty4Framer {

  def bufferManagerName: String = "muxPipelineInit"

  def MessageDecoderName = "ByteBufToByteReader"

  def BufEncoderName = "BufToByteBufEncoder"

  // Note: this is sharable by default.
  val bufferManager: ChannelHandler = new ChannelInitializer[Channel] {
    override def initChannel(ch: Channel): Unit = {
      val pipeline = ch.pipeline()

      pipeline.addLast(MessageDecoderName, CopyingByteReaderDecoder)
      pipeline.addLast(BufEncoderName, OutboundBufEncoder)
    }
  }

  @Sharable
  private[this] object OutboundBufEncoder extends ChannelOutboundHandlerAdapter {
    override def write(ctx: ChannelHandlerContext, msg: scala.Any, promise: ChannelPromise): Unit =
      BufCodec.write(ctx, msg, promise)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy