Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error not found value context?

def join(username: String): scala.concurrent.Future[(Iteratee[JsValue, _], Enumerator[JsValue])] = {
  println("friend name in model" + username)
  val first = Akka.system.actorOf(Props[ChatRoom2], name = username)
  println("this is chat room two default")
}    

and when i use this val first = context.actorOf(Props[ChatRoom2],name=username)

I am use this for create a child actor in a different chat room but it shows an error not found value context.

like image 663
harish Avatar asked Apr 03 '14 07:04

harish


2 Answers

You cannot access actor context from a class not extending Actor. You must be extending Actor in the class having join method above (not only ChatRoom2)

like image 58
mesutozer Avatar answered Nov 14 '22 13:11

mesutozer


When you use an actor system reference, you're creating "top level" actors, whereas using context creates "child actors" of your current actor. This means that accessing context only makes sense from within an Actor.

Here's an example:

val system = ActorSystem("name")
val act = system.actorOf(classOf[SomeActor])

class SomeActor extends Actor {
  def receive = {
    case _ => val child = context.actorOf(...)
  }
}

In this example "act" is a "top level" actor, and "child" is a child of "act", because it was created by act's context.

I hope this helps!

For more help please refer to the docs: http://doc.akka.io/docs/akka/2.3.1/scala/actors.html

like image 3
Konrad 'ktoso' Malawski Avatar answered Nov 14 '22 11:11

Konrad 'ktoso' Malawski