Permalink
Browse files

LiftPipelineFactory

move boot code and pipeline factory to its own class. cleaned up example.
  • Loading branch information...
1 parent 3db01b7 commit cd63189afb2ee47e545a54f150f258e02fde7b3b @jrwest committed Feb 24, 2012
@@ -64,7 +64,7 @@ class LiftChannelHandler(val nettyContext: HTTPNettyContext,
reqVarProvider(Empty,{
- val httpRequest: HTTPRequest = new NettyHttpRequest(request, ctx, nettyContext, this) // FIXME new HTTPRequestServlet(httpReq, this)
+ val httpRequest: HTTPRequest = new NettyHttpRequest(request, ctx, nettyContext, this)
val httpResponse = new NettyHttpResponse(ctx)
handleLoanWrappers(service(httpRequest, httpResponse) {
@@ -6,10 +6,7 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory
import java.util.concurrent.Executors
import org.jboss.netty.bootstrap.ServerBootstrap
import java.net.InetSocketAddress
-import org.jboss.netty.channel.{Channels, ChannelPipeline, ChannelPipelineFactory, ChannelFactory}
-import net.liftweb.util.Helpers
-import net.liftweb.http.{LiftRules, LiftServlet}
-import net.liftweb.common.{Empty, Box}
+import org.jboss.netty.channel.ChannelFactory
/**
* Created by IntelliJ IDEA.
@@ -18,8 +15,6 @@ import net.liftweb.common.{Empty, Box}
* Time: 10:04 PM
*/
-import MyTypes._
-
object LiftNettyExampleServer extends App {
val allChannels = new DefaultChannelGroup("lift-netty-example-server")
@@ -29,37 +24,9 @@ object LiftNettyExampleServer extends App {
Executors.newCachedThreadPool()
)
- private def findObject(cls: String): Box[AnyRef] =
- Helpers.tryo[Class[_]](Nil)(Class.forName(cls + "$")).flatMap {
- c =>
- Helpers.tryo {
- val field = c.getField("MODULE$")
- field.get(null)
- }
- }
-
- val transientVarProvider: VarProvider =
- findObject("net.liftweb.http.TransientRequestVarHandler").open_!.asInstanceOf[VarProvider]
- val reqVarProvider: VarProvider =
- findObject("net.liftweb.http.RequestVarHandler").open_!.asInstanceOf[VarProvider]
-
- val nettyContext = new HTTPNettyContext
-
- val liftLand = new LiftServlet(nettyContext)
-
- LiftRules.setContext(nettyContext)
-
private[this] val bootstrap = new ServerBootstrap(factory)
- val handler = new LiftChannelHandler(nettyContext, transientVarProvider, reqVarProvider, liftLand)
-
- bootstrap.setPipelineFactory(new ChannelPipelineFactory {
- def getPipeline: ChannelPipeline = Channels.pipeline(
- new HttpRequestDecoder,
- new HttpResponseEncoder,
- handler
- )
- })
+ bootstrap.setPipelineFactory(new LiftPipelineFactory)
bootstrap.setOption("child.tcpNoDelay", true)
bootstrap.setOption("child.keepAlive", true)
@@ -0,0 +1,49 @@
+package com.something.lift
+
+import org.jboss.netty.handler.codec.http.{HttpResponseEncoder, HttpRequestDecoder}
+import net.liftweb.common.Box
+import net.liftweb.util.Helpers
+import net.liftweb.http.{LiftRules, LiftServlet}
+import org.jboss.netty.channel.{Channels, ChannelPipeline, ChannelPipelineFactory}
+
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: jordanrw
+ * Date: 2/23/12
+ * Time: 9:55 PM
+ */
+
+import MyTypes._
+class LiftPipelineFactory extends ChannelPipelineFactory {
+
+ // TODO make better, extensible, etc
+ def getPipeline: ChannelPipeline = Channels.pipeline(
+ new HttpRequestDecoder,
+ new HttpResponseEncoder,
+ handler
+ )
+
+ val transientVarProvider: VarProvider =
+ findObject("net.liftweb.http.TransientRequestVarHandler").open_!.asInstanceOf[VarProvider]
+ val reqVarProvider: VarProvider =
+ findObject("net.liftweb.http.RequestVarHandler").open_!.asInstanceOf[VarProvider]
+
+ val nettyContext = new HTTPNettyContext
+
+ val liftLand = new LiftServlet(nettyContext)
+
+ LiftRules.setContext(nettyContext)
+
+ val handler = new LiftChannelHandler(nettyContext, transientVarProvider, reqVarProvider, liftLand)
+
+ private def findObject(cls: String): Box[AnyRef] =
+ Helpers.tryo[Class[_]](Nil)(Class.forName(cls + "$")).flatMap {
+ c =>
+ Helpers.tryo {
+ val field = c.getField("MODULE$")
+ field.get(null)
+ }
+ }
+
+}

0 comments on commit cd63189

Please sign in to comment.