Application.scala 881 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package controllers
  2. import play._
  3. import play.api.libs.concurrent._
  4. import play.api.mvc._
  5. import play.libs.Json
  6. import org.codehaus.jackson.node.ObjectNode
  7. import views.html._
  8. import models._
  9. import java.util._
  10. import java.util.concurrent.ThreadLocalRandom
  11. import scala.concurrent._
  12. object Application extends Controller {
  13. private val TEST_DATABASE_ROWS = 10000
  14. def json() = Action {
  15. val result = Json.newObject()
  16. result.put("message", "Hello World!")
  17. Ok(result.toString)
  18. }
  19. def db(queries: Int) = Action {
  20. import play.api.libs.concurrent.Execution.Implicits._
  21. val random = ThreadLocalRandom.current()
  22. Async {
  23. Future {
  24. (1 to queries) map {
  25. _ =>
  26. World.find.byId(random.nextInt(TEST_DATABASE_ROWS) + 1)
  27. }
  28. } map {
  29. worlds =>
  30. Ok(Json.toJson(worlds).toString())
  31. }
  32. }
  33. }
  34. }