Created
February 10, 2014 18:04
-
-
Save caniszczyk/8921026 to your computer and use it in GitHub Desktop.
Netty based Listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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