Browse Source

upgrade to latest versions of Play, Scala & Sbt, clean up and tuning runtime & build configurations

Andriy Plokhotnyuk 9 years ago
parent
commit
f4e40a3211

+ 0 - 23
frameworks/Scala/play2-scala/play2-scala/app/Filters.scala

@@ -1,23 +0,0 @@
-import javax.inject.{Singleton, Inject}
-
-import play.api.http.HttpFilters
-import play.api.mvc.{RequestHeader, EssentialAction, EssentialFilter}
-import play.api.libs.concurrent.Execution.Implicits.defaultContext
-import play.mvc.Http
-
-@Singleton()
-class Filters @Inject() (headerFilter: HeaderFilter) extends HttpFilters {
-  override def filters: Seq[EssentialFilter] = Seq(
-    headerFilter)
-}
-
-@Singleton
-class HeaderFilter extends EssentialFilter {
-  def apply(next: EssentialAction) = new EssentialAction {
-    def apply(request: RequestHeader) = {
-      next(request).map(result =>
-        result.withHeaders(Http.HeaderNames.SERVER -> "EXAMPLE")  // Only here to address the WARN about this header.
-      )
-    }
-  }
-}

+ 8 - 12
frameworks/Scala/play2-scala/play2-scala/app/controllers/Application.scala

@@ -1,29 +1,25 @@
 package controllers
 
 import javax.inject.Singleton
-
+import akka.util.CompactByteString
+import play.api.http.HttpEntity.Strict
 import play.api.mvc._
 import play.api.libs.json.Json
+import play.mvc.Http
 
 @Singleton
 class Application extends Controller {
-
-  // Test seems picky about headers.  Doesn't like character set being there for JSON.  Always wants Server header set.
-  // There is a Filter which adds the Server header for all types.  Below I set Content-Type as needed to get rid of
-  // warnings.
-
-  // Easy ones
-  case class HelloWorld(message: String)
+  val header = ResponseHeader(OK, Map(Http.HeaderNames.SERVER -> "EXAMPLE"))
   implicit val helloWorldWrites = Json.writes[HelloWorld]
 
   def getJsonMessage = Action {
     val helloWorld = HelloWorld(message = "Hello, World!")
-    Ok(Json.toJson(helloWorld)).withHeaders(CONTENT_TYPE -> "application/json")
+    Result(header, Strict(CompactByteString(Json.toJson(helloWorld).toString()), Some("application/json")))
   }
 
   val plaintext = Action {
-    // default headers are correct according to docs: charset included.
-    // BUT the test harness has a WARN state and says we don't need it.
-    Ok("Hello, World!").withHeaders(CONTENT_TYPE -> "text/plain")
+    Result(header, Strict(CompactByteString("Hello, World!"), Some("text/plain")))
   }
 }
+
+case class HelloWorld(message: String)

+ 2 - 8
frameworks/Scala/play2-scala/play2-scala/build.sbt

@@ -2,12 +2,6 @@ name := "play2-scala"
 
 version := "1.0-SNAPSHOT"
 
-scalaVersion := "2.11.7"
+scalaVersion := "2.11.8"
 
-lazy val root = (project in file(".")).enablePlugins(PlayScala)
-
-resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
-
-// Play provides two styles of routers, one expects its actions to be injected, the
-// other, legacy style, accesses its actions statically.
-routesGenerator := InjectedRoutesGenerator
+val root = (project in file(".")).enablePlugins(PlayScala)

+ 22 - 0
frameworks/Scala/play2-scala/play2-scala/conf/application.conf

@@ -42,3 +42,25 @@ play.i18n.langs = [ "en" ]
 
 # You can disable evolutions for a specific datasource if necessary
 # play.evolutions.db.default.enabled=false
+
+play.server {
+  netty {
+    transport = "native"   # should be "jdk" for non-Linux platforms
+  }
+}
+
+akka {
+  log-dead-letters = off
+  actor {
+    default-dispatcher {
+      fork-join-executor {
+        parallelism-min = 1
+        parallelism-factor = 0.5  # don't overuse CPU by context swiching, thread contention & spinning
+        parallelism-max = 16
+      }
+    }
+    default-mailbox {
+      mailbox-type = "akka.dispatch.SingleConsumerOnlyUnboundedMailbox"
+    }
+  }
+}

+ 1 - 1
frameworks/Scala/play2-scala/play2-scala/project/build.properties

@@ -1 +1 @@
-sbt.version=0.13.9
+sbt.version=0.13.11

+ 1 - 4
frameworks/Scala/play2-scala/play2-scala/project/plugins.sbt

@@ -1,8 +1,5 @@
 // Comment to get more information during initialization
 logLevel := Level.Warn
 
-// The Typesafe repository 
-resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
-
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.0")

+ 1 - 1
frameworks/Scala/play2-scala/setup_scala.sh

@@ -12,4 +12,4 @@ rm -rf ${TROOT}/play2-scala/target/universal/stage/RUNNING_PID
 sbt stage
 
 # Execute Start script in background.
-${TROOT}/play2-scala/target/universal/stage/bin/play2-scala &
+${TROOT}/play2-scala/target/universal/stage/bin/play2-scala -J-server -J-Xms1g -J-Xmx1g -J-XX:NewSize=512m -J-XX:+UseG1GC -J-XX:MaxGCPauseMillis=30 -J-XX:-UseBiasedLocking -J-XX:+AlwaysPreTouch &