Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
Initial version of smart http netty implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Bardadym <denis.bardadym@acenture.com>
  • Loading branch information
Denis Bardadym committed Apr 10, 2012
1 parent ada9033 commit d0bebdf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ libraryDependencies ++= Seq (
"net.liftweb" %% "lift-mongodb-record" % "2.5-SNAPSHOT" % "compile",
"com.foursquare" %% "rogue" % "1.1.6" intransitive(),
"org.eclipse.jetty" % "jetty-webapp" % "8.0.4.v20111024" % "container",
"ch.qos.logback" % "logback-classic" % "1.0.0"
"ch.qos.logback" % "logback-classic" % "1.0.0",
"io.netty" % "netty" % "3.3.1.Final" % "compile"
)

(resourceManaged in (Compile, LessKeys.less)) <<= (sourceDirectory in Compile)(_ / "webapp" / "assets")
82 changes: 82 additions & 0 deletions src/main/scala/daemon/http/daemon.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2012 Denis Bardadym
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package daemon.http

import net.liftweb.common.Loggable

import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory
import org.jboss.netty.channel.{ChannelPipelineFactory, Channels, SimpleChannelHandler,ChannelHandlerContext, ExceptionEvent, MessageEvent}
import org.jboss.netty.handler.codec.http.{HttpServerCodec, HttpChunkAggregator, HttpRequest}
import org.jboss.netty.bootstrap.ServerBootstrap
import org.jboss.netty.util.CharsetUtil

import java.net.InetSocketAddress
import java.util.concurrent.Executors

import code.model.RepositoryDoc

object SmartHttpDaemon extends daemon.Service with Loggable {

var inited = false

def init() {
val factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool, Executors.newCachedThreadPool)

val bootstrap = new ServerBootstrap(factory)

bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
def getPipeline() = {
val pipeline = Channels.pipeline

pipeline.addLast("codec", new HttpServerCodec )
pipeline.addLast("aggregator", new HttpChunkAggregator(5242880))
pipeline.addLast("authHandler", new SmartHttpMessageHandler )

pipeline
}
})

//b.setOption("localAddress", new InetSocketAddress(8080))

bootstrap.setOption("reuseAddress", true)
bootstrap.setOption("child.tcpNoDelay", true)
bootstrap.setOption("child.keepAlive", true)

bootstrap.bind(new InetSocketAddress(80));


}

def shutdown() {}



def repoUrlForCurrentUser(r: RepositoryDoc) = ""

}

class SmartHttpMessageHandler extends SimpleChannelHandler with Loggable {
override def exceptionCaught(ctx: ChannelHandlerContext, e: ExceptionEvent) {
logger.error("Exception recieved in smart http daemon", e.getCause)
ctx.getChannel.close
}

override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
val httpResponse = e.getMessage.asInstanceOf[HttpRequest]
val json = httpResponse.getContent.toString(CharsetUtil.UTF_8)
logger.debug(json)
}
}

0 comments on commit d0bebdf

Please sign in to comment.