I will change it to val, thank you On Tuesday, February 11, 2014 8:58:45 AM UTC-2, Akka Team wrote: > > Hi Diego, > > apart from style questions (like using a sealed State trait instead of an > Int), there is just one thing: you might want to use `val` instead of `def` > when declaring the supervisorStrategy in general, unless you consciously > did it here because failure is so rare that the allocation should better > happen only in that case. > > Regards, > > Roland > > > > On Mon, Feb 10, 2014 at 6:51 PM, Diego Balduini > <[email protected]<javascript:> > > wrote: > >> Hello >> >> I want to swap between two cache implementations. >> When the first fails, it swap to the second. >> This is what i've came to. It works, but i wanna know if you guys have a >> better way of doing this, because it seems that this solution is not a good >> practice. >> >> // Actor >> >> val redisActor = context.actorOf(Props[RedisActor], "redis") >> val memcachedActor = context.actorOf(Props[MemcachedActor], "memcached") >> >> var cache: ActorRef = memcachedActor >> var state = 0 >> >> override def supervisorStrategy = { >> def swap() = state match { >> case 0 => >> state = 1 >> cache = redisActor >> Stop >> case _ => Escalate >> } >> >> OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { >> case e: java.net.ConnectException => swap >> case e: ActorInitializationException => swap >> } >> } >> >> >> >> >> -- >> >>>>>>>>>> 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] <javascript:>. >> To post to this group, send email to [email protected]<javascript:> >> . >> Visit this group at http://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > > -- > Akka Team > Typesafe - The software stack for applications that scale > Blog: letitcrash.com > Twitter: @akkateam >
-- >>>>>>>>>> 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.
