PageRenderTime 242ms CodeModel.GetById 30ms RepoModel.GetById 3ms app.codeStats 0ms

/src/main/g8/src/main/scala/com/$domain_name$/$product_name$/$name$/actor/$actor_name$.scala

https://github.com/itam/scala_akka_mongo.g8
Scala | 43 lines | 35 code | 8 blank | 0 comment | 0 complexity | 51cfbf571bbf7c99693778f3104ab183 MD5 | raw file
  1. package com.$domain_name$.$product_name$.$name$.actor
  2. import akka.dispatch.Dispatchers
  3. import com.mongodb.casbah.Imports._
  4. import com.mongodb.casbah.commons.MongoDBObject
  5. import akka.actor.Actor._
  6. import akka.routing._
  7. import com.$domain_name$.$product_name$.$name$.{Fetch, Persist, Update}
  8. import org.bson.types.ObjectId
  9. import com.$domain_name$.$product_name$.$name$.model.$model_name$
  10. object $actor_name${
  11. val dispatcher = Dispatchers.newExecutorBasedEventDrivenWorkStealingDispatcher("$actor_name$-dispatcher").build
  12. }
  13. class $actor_name$(poolSize: Int, collection: MongoCollection) extends Actor with DefaultActorPool
  14. with FixedCapacityStrategy
  15. with SmallestMailboxSelector {
  16. def receive = _route
  17. def limit = 10
  18. def partialFill = true
  19. def selectionCount = 1
  20. self.dispatcher = $actor_name$.dispatcher
  21. def instance = actorOf(new Actor() {
  22. def receive = {
  23. case "test" => println("You found my test case!")
  24. case "post" => {
  25. println("POSTing some random text.")
  26. collection.insert(MongoDBObject("randomText" -> "POSTING some random text"))
  27. }
  28. case f: Fetch[ObjectId] => {
  29. val dbo = collection.findOne(MongoDBObject("_id" -> f.value))
  30. self.channel ! grater[$model_name$].asObject(dbo.get)
  31. }
  32. case _ => println("received unknown msg")
  33. }
  34. })
  35. }