Skip to content

Instantly share code, notes, and snippets.

@caniszczyk
Created February 10, 2014 18:06
Show Gist options
  • Save caniszczyk/8921074 to your computer and use it in GitHub Desktop.
Save caniszczyk/8921074 to your computer and use it in GitHub Desktop.
Bridge Netty and Finagle
class ServerBridge[In, Out](
serveTransport: Transport[In, Out] => Unit,
) extends SimpleChannelHandler {
override def channelOpen(
ctx: ChannelHandlerContext,
e: ChannelStateEvent
){
val channel = e.getChannel
val transport = new ChannelTransport[In, Out](channel) // #1
serveTransport(transport)
super.channelOpen(ctx, e)
}
override def exceptionCaught(
ctx: ChannelHandlerContext,
e: ExceptionEvent
) { // log exception and close channel }
}
// #1 Is called once a new Channel was open and create a new ChannelTransport to bridge to Finagle
// see https://github.com/twitter/finagle/blob/master/finagle-core/src/main/scala/com/twitter/finagle/netty3/server.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment