Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Netty3 based Transport in Finagle
case class Netty3Transporter[In, Out](
pipelineFactory: ChannelPipelineFactory,
newChannel: ChannelPipeline => Channel =
Netty3Transporter.channelFactory.newChannel(_),
newTransport: Channel => Transport[In, Out] =
new ChannelTransport[In, Out](_),
// various timeout/ssl options
) extends (
(SocketAddress, StatsReceiver) => Future[Transport[In, Out]]
){
private def newPipeline(
addr: SocketAddress,
statsReceiver: StatsReceiver
)={
val pipeline = pipelineFactory.getPipeline()
// add stats, timeouts, and ssl handlers
pipeline // #1
}
private def newConfiguredChannel(
addr: SocketAddress,
statsReceiver: StatsReceiver
)={
val ch = newChannel(newPipeline(addr, statsReceiver))
ch.getConfig.setOptions(channelOptions.asJava)
ch
}
def apply(
addr: SocketAddress,
statsReceiver: StatsReceiver
): Future[Transport[In, Out]] = {
val conn = new ChannelConnector[In, Out](
() => newConfiguredChannel(addr, statsReceiver),
newTransport, statsReceiver) // #2
conn(addr)
} }
// #1 Create a new ChannelPipeline and add the needed handlers
// #2 Create a new ChannelConnector which is used internally
// see https://github.com/twitter/finagle/blob/master/finagle-core/src/main/scala/com/twitter/finagle/netty3/client.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.