Skip to content

Instantly share code, notes, and snippets.

@caniszczyk
Created February 10, 2014 18:04

Revisions

  1. caniszczyk created this gist Feb 10, 2014.
    30 changes: 30 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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