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].
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