Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Netty based Listener
case class Netty3Listener[In, Out](
pipelineFactory: ChannelPipelineFactory,
channelFactory: ServerChannelFactory
bootstrapOptions: Map[String, Object], ... // stats/timeouts/ssl config
) extends Listener[In, Out] {
def newServerPipelineFactory(
statsReceiver: StatsReceiver, newBridge: () => ChannelHandler
) = new ChannelPipelineFactory { // #1
def getPipeline() = {
val pipeline = pipelineFactory.getPipeline()
// ... add stats/timeouts/ssl
pipeline.addLast("finagleBridge", newBridge()) // #2
pipeline
}
}
def listen(addr: SocketAddress)(
serveTransport: Transport[In, Out] => Unit
): ListeningServer =
new ListeningServer with CloseAwaitably {
val newBridge = () => new ServerBridge(serveTransport, ...)
val bootstrap = new ServerBootstrap(channelFactory)
bootstrap.setOptions(bootstrapOptions.asJava)
bootstrap.setPipelineFactory(
newServerPipelineFactory(scopedStatsReceiver, newBridge))
val ch = bootstrap.bind(addr)
}
}
}
// #1 Create a new ChannelPipelineFactory
// #2 Add the Bridge into the ChannelPipeline
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.