Hi Oleg,
I will try doing something with become like your sample and see whats
happens.
Thank you for the reply
On Monday, February 10, 2014 7:27:31 PM UTC-2, Oleg Zhurakousky wrote:
>
> What if you consider Hot Swap Actor, then you could rely on
> become(behavior).
> Pseudo-coding:
> class CacheHotSwapActor extends Actor {
> def memCacheReceiveLoop:Receive = {
> // your code
> }
> def redisReceiveLoop:Receive = {
> // your code
> }
> def receive = {
> case java.net.ConnectException =>
> become(memCacheReceiveLoop)
> case ActorInitializationException =>
> become(memCacheReceiveLoop)
> case _ => become(redisReceiveLoop)
> }
> }
>
> At least this way you'd avoid vars and whatever problems it may lead to.
>
> Cheers
> Oleg
>
>
> On Mon, Feb 10, 2014 at 12: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.
>>
>
>
--
>>>>>>>>>> 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.