The latest recommended practise is to use a props factory method in the
companion object.
See example here:
http://doc.akka.io/docs/akka/2.3.0-RC4/scala/actors.html#Recommended_Practices

In the factory method you can use default parameter values.

Regards,
Patrik


On Thu, Feb 20, 2014 at 9:49 PM, Edwin Fuquen <[email protected]> wrote:

> Apologies if this has been discussed before, but I did a search and
> couldn't find anyone mentioning this issue.  There are a couple of ways to
> construct an actor now, most of which has been depreciated in favor of a
> Props(classOf[MyActor]) style.  However, if the Actor has default arguments
> set and you call it with that style with those arguments missing you will
> get an error.  I've made a test case in this rep:
>
> https://github.com/efuquen/akka-default-arg-construction
>
> The output of the test, which should provide enough detail of the
> situation, follows:
>
> This:
> class TestActor(pongMessage: String, defaultArg: Int = 2)
> should be a valid constructor for:
> Props(classOf[TestActor], "ponggggg!!!")
> But failed with:
> java.lang.IllegalArgumentException: no matching constructor found on class
> com.parascal.akka.TestActor for arguments [class java.lang.String]
> at akka.util.Reflect$.error$1(Reflect.scala:82)
> at akka.util.Reflect$.findConstructor(Reflect.scala:106)
> at akka.actor.ArgsReflectConstructor.<init>(Props.scala:347)
> at akka.actor.IndirectActorProducer$.apply(Props.scala:306)
> at akka.actor.Props.producer(Props.scala:173)
> at akka.actor.Props.<init>(Props.scala:186)
> at akka.actor.Props$.apply(Props.scala:93)
> at com.parascal.akka.Main$.main(Main.scala:16)
> at com.parascal.akka.Main.main(Main.scala)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at sbt.Run.invokeMain(Run.scala:72)
> at sbt.Run.run0(Run.scala:65)
> at sbt.Run.sbt$Run$$execute$1(Run.scala:54)
> at sbt.Run$$anonfun$run$1.apply$mcV$sp(Run.scala:58)
> at sbt.Run$$anonfun$run$1.apply(Run.scala:58)
> at sbt.Run$$anonfun$run$1.apply(Run.scala:58)
> at sbt.Logger$$anon$4.apply(Logger.scala:90)
> at sbt.TrapExit$App.run(TrapExit.scala:244)
> at java.lang.Thread.run(Thread.java:724)
> It will succeed with:
> Props(classOf[TestActor], "ponggggg!!!", 2)
> ponggggg!!!
>
>
> I imagine this is due to a reflection issue on the actor, but I don't see
> any reason this shouldn't be taken into account.  It's a bit frustrating as
> I've had to fallback to a deprecated way of constructing actors, i.e.
> Props(new TestActor("ponggg!!!")).  Is this a known issue, has anyone else
> come across it?
>
> --
> >>>>>>>>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 

Patrik Nordwall
Typesafe <http://typesafe.com/> -  Reactive apps on the JVM
Twitter: @patriknw

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to