Hi,

this illustrates how traits and self types work in Scala. I do not have
deep knowledge of inner workings of Scala, but you can workaround your
issue by introducing another trait
<https://github.com/2m/akka-actor-sandbox/blob/0974a0cda77f54fef8c565f4f02fa503ed529444/src/main/scala/LifecycleTrait.scala>
.

On Sun, Nov 9, 2014 at 9:35 AM, 何品 <[email protected]> wrote:

> The trait seems can't override the actor's lifecycle hook,cause the
> override will cause the lifecycle hook come to be apart of the trait,which
> will cause probleam,when we mixin trait to some other actor witch need the
> hook too.
> I think the best practice maybe ,1 no override the actor's lifecycle
> hook,2 provide some trait level lifecycle hook for the user to call.
>
>
>
> 在 2014年11月9日星期日UTC+8下午3时15分30秒,何品写道:
>
>> Hi,the code blow cause the StackOverFlow error,but if I want to do
>> something useful in an trait and let the actor who want to use mixin it,and
>> that trait need to do some initialize witch need to hook the actor's
>> lifecycle ,then what the best practice?
>> The problem of the code blow is that it will cause the
>> StackOverFlow,that's really definite wrong.
>>
>>
>> trait UsefulTrait {actor:Actor =>
>>   @throws[Exception](classOf[Exception])
>>   override def preStart(): Unit = {
>>     //do some thing here
>>     actor.preStart()
>>   }
>>
>> }
>>
>> class UsefulActor extends Actor with UsefulTrait{
>>   override def receive: Receive = {
>>     case msg => //handle it
>>   }
>>
>>   @throws[Exception](classOf[Exception]) override
>>   def preStart(): Unit = {
>>     //do some thing here too
>>     super.preStart()
>>   }
>> }
>>
>>  --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> 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/d/optout.
>



-- 
Martynas Mickevičius
Typesafe <http://typesafe.com/> – Reactive
<http://www.reactivemanifesto.org/> Apps on the JVM

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      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/d/optout.

Reply via email to