Akka [2.2.3] Setting Actor names

889 views
Skip to first unread message

David Holtzhouser

unread,
Nov 14, 2013, 3:23:01 PM11/14/13
to akka...@googlegroups.com
Just starting to learn Akka and really Scala as well...maybe not the smartest ordering of things.

I must be missing something very obvious, but I just can't seem to find it.

I'm trying to set the Actor's name when it is created, but the Info logging doesn't seem to be displaying it, instead using a system generated name:


[INFO] [11/14/2013 14:05:09.747] [BizRulesSystem-akka.actor.default-dispatcher-4] [akka://BizRulesSystem/user/$a] akka.actor.RepointableActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-8] [akka://BizRulesSystem/user/$a/$a] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-7] [akka://BizRulesSystem/user/$a/$b] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-4] [akka://BizRulesSystem/user/$a/$c] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-2] [akka://BizRulesSystem/user/$a/$e] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-6] [akka://BizRulesSystem/user/$a/$f] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-2] [akka://BizRulesSystem/user/$a/$g] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-7] [akka://BizRulesSystem/user/$a/$d] akka.actor.LocalActorRef receiving message

Forgive the ugly, non-idiomatic Scala code below (remember, just learning here).
What is the proper way to name the runtime Actors, such that the logs look like:

[INFO] [11/14/2013 14:05:09.747] [BizRulesSystem-akka.actor.default-dispatcher-4] [akka://BizRulesSystem/user/SomeName] akka.actor.RepointableActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-8] [akka://BizRulesSystem/user/SomeName/QualifierA] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-7] [akka://BizRulesSystem/user/SomeName/QualifierB] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-4] [akka://BizRulesSystem/user/SomeName/QualifierC] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-2] [akka://BizRulesSystem/user/SomeName/QualifierD] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-6] [akka://BizRulesSystem/user/SomeName/QualifierE] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-2] [akka://BizRulesSystem/user/SomeName/QualifierF] akka.actor.LocalActorRef receiving message
[INFO] [11/14/2013 14:05:09.754] [BizRulesSystem-akka.actor.default-dispatcher-7] [akka://BizRulesSystem/user/SomeName/QualifierG] akka.actor.LocalActorRef receiving message

Qualifier.scala
trait Qualifier extends Actor with ActorLogging {

  def name : String
  def description: String
  def qualifierList: Vector[String]
}

Includes.scala
class Includes(val name: String, val description: String, val qualifierList: Vector[String]) extends Qualifier {

  def +> : Boolean = {

    true
  }
}

Excludes.scala
class Excludes(val name: String, val description: String, val qualifierList: Vector[String]) extends Qualifier {

  def +>(): Boolean = {

    true
  }
}


BaseBusinessRule.scala

class BaseBusinessRule private (val qualifiers: Vector[BizQualifier], val approvedTx: Vector[Long], val deniedTx: Vector[Long])
  extends BusinessRule  {

  def this(activityBusinessRuleName: String) = {
    this(Vector.empty, Vector.empty, Vector.empty)
    val qualSvc = new QualifierService
    val includes = qualSvc.getIncludeQualifers(activityBusinessRuleName)
    val excludes = qualSvc.getExcludeQualifiers(activityBusinessRuleName)
    val qualifiers = includes ++ excludes

    for (q <- qualifiers) {
      if (q.isInstanceOf[Includes]) {
        context.actorOf(Props(classOf[business_rules.actors.Includes], q.name, q.description, q.qualifierList))
      }
      if (q.isInstanceOf[Excludes]) {
        context.actorOf(Props(classOf[business_rules.actors.Excludes], q.name, q.description, q.qualifierList))
      }
    }
  }


'RunnerCode.scala'

object GreeterRunner extends App {

  runGreeter()

  def runGreeter() {
    // there is a third 'root guardian' that the system and user 
    // guardians 'report' to

    //implicit 'system guardian' of the entire actor system
    val system = ActorSystem("BizRulesSystem")

    // /user guardian actor
    val bizRuleActor = system.actorOf(Props(classOf[BaseBusinessRule], "SomeName"))

    bizRuleActor ! "test"

  }
}

Thank you for any assistance.

Roland Kuhn

unread,
Nov 14, 2013, 3:33:00 PM11/14/13
to akka...@googlegroups.com
Hi David,

you’re sooo close: just use the two-arg version of actorOf and don’t pass the name into the Actor—the constructor runs long after the name has been set in stone.

system.actorOf(Props[BaseBusinessRule], "SomeName") // you’ll have to make a no-arg constructor for this line to work

Regards,

Roland

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


√iktor Ҡlang

unread,
Nov 14, 2013, 4:41:02 PM11/14/13
to Akka User List
I think this example leaves a bit to be desired: http://doc.akka.io/docs/akka/2.2.3/scala/actors.html#Recommended_Practices

Cheers,
--
Cheers,

Viktor Klang

Director of Engineering

Twitter: @viktorklang

David Holtzhouser

unread,
Nov 14, 2013, 4:58:45 PM11/14/13
to akka...@googlegroups.com
Roland,

Thank you for your prompt reply.

I believe I have figured out what my issue was.

val props = Props(classOf[MyActor], arg1, arg2)

newProps(deploy: Deployclazz: Class[_]args: Seq[Any])


The example from the Akka api docs didn't really make it clear (to a newbie) that I could do this:

val bizRuleActor = system.actorOf(Props(classOf[BaseBusinessRule],"SomeName"), "SomeName")

and

    for (q <- qualifiers) {
      if (q.isInstanceOf[com.maritz.qualifiers.Includes]) {
        context.actorOf(Props(classOf[business_rules.actors.Includes], q.qName, q.description, q.qualifierList), q.qName)
      }
      if (q.isInstanceOf[com.maritz.qualifiers.Excludes]) {
        context.actorOf(Props(classOf[business_rules.actors.Excludes], q.qName, q.description, q.qualifierList), q.qName)
      }
    }

where I now believe that the code in red is actually what is passed into the Actor constructor.  

Thanks,

Dave

Roland Kuhn

unread,
Nov 14, 2013, 5:10:27 PM11/14/13
to akka...@googlegroups.com
Yes, indeed, will fix.
Reply all
Reply to author
Forward
0 new messages