Hi Andreas,

To be able to migrate actors you need to be able to restore their state at
their new place. This is one of the use-cases for the new experimental
akka-persistence module (
http://doc.akka.io/docs/akka/2.3.0/scala/persistence.html).

Migrating entities is not trivial, so before you start implementing your
own migration logic, take a look at cluster sharding to see if it is a fit
for your problem:
http://doc.akka.io/docs/akka/2.3.0/contrib/cluster-sharding.html

Sharding allows custom allocation strategies, (see the doc page I linked
above) it might be just what you need.

-Endre


On Tue, Mar 25, 2014 at 2:35 PM, Andreas Moregard <
andreas.moreg...@gmail.com> wrote:

> Hello!
>
> I have been trying to find information on how to move/migrate a running
> actor from one node to another
> but I have not been able to find anything concrete.
>
> Assume we have three actors, the producer, the processor and the consumer.
> The producer
> creates/senses/reads data and sends it to the processor, the processor
> processes this data
> and sends it to the consumer that logs/saves it.
>
> Communication chain:
> ProducerActor -> ProcessActor -> ConsumerActor
>
> For the context:
> Assume we had the three nodes 6000,6001,6002 running when we initially
> deployed the actors.
> After a while, node 6003 enters the cluster. We now realize that node 6003
> is a much better
> candidate for running the ProcessActor, so we would like to move/migrate
> it.
>
> I looked at the 
> SimpleClusterApp<https://github.com/akka/akka/blob/master/akka-samples/akka-sample-cluster-scala/src/main/scala/sample/cluster/simple/SimpleClusterApp.scala>
>  and
> I just changed it around a bit in order to try out some stuff:
>
> object SimpleClusterApp {
>   def main(args: Array[String]): Unit = {
>     if (args.isEmpty)
>       startup(Seq("6000", "6001", "6002", "6003"))
>     else
>       startup(args)
>   }
>
>   def startup(ports: Seq[String]): Unit = {
>     ports foreach { port =>
>       // Override the configuration of the port
>       val config = ConfigFactory.parseString("akka.remote.netty.tcp.port="
> + port).
>         withFallback(ConfigFactory.load())
>
>       // Create an Akka system
>       val system = ActorSystem("ClusterSystem", config)
>       // Create an actor that handles cluster domain events
>       system.actorOf(Props[ClusterListener], name = "clusterListener")
>
>
>
>       if(port == "0") {
>         // Set adresses for the four nodes
>         val producerAddr = AddressFromURIString("akka.tcp://
> ClusterSystem@127.0.0.1:6000")
>         val processAddr = AddressFromURIString("akka.tcp://
> ClusterSystem@127.0.0.1:6001")
>         val consumerAddr = AddressFromURIString("akka.tcp://
> ClusterSystem@127.0.0.1:6002")
>         val newAddr = AddressFromURIString("akka.tcp://
> ClusterSystem@127.0.0.1:6003")
>
>         // Deploy the actors
>         val consumerRef =
> system.actorOf(Props[ConsumerActor].withDeploy(Deploy(scope =
> RemoteScope(consumerAddr))), name = "Consumer")
>         val processRef =
> system.actorOf(Props(classOf[ProcessActor],consumerRef).withDeploy(Deploy(scope
> = RemoteScope(processAddr))), name = "ProcessingResource")
>         val producerRef =
> system.actorOf(Props(classOf[ProducerActor],processRef).withDeploy(Deploy(scope
> = RemoteScope(producerAddr))), name = "Producer")
>
>         // Tell producer to start producing values
>         producerRef ! Start
>
>         // migrate processRef to newAddr
>       }
>     }
>   }
> }
>
> If it is Stateless I could just do something like:
>
>
> //temporarily halt production
> producerRef ! Halt
>
>
>
> // shut down processRef
> processRef ! Stop
>
> //create new processing resource
>  val newRef =
> system.actorOf(Props(classOf[ProcessActor],consumerRef).withDeploy(Deploy(scope
> = RemoteScope(newAddr))), name = "ProcessingResource")
>
>
>
> //redirect producer output to new processing resource
> producerRef ! ChangeOutput(newRef)
>
>
>
> //restart production
> producerRef ! "Start"
>
>
>
> Basically, how do I move/migrate the actor ProcessingResource to newAddr
> if it has a state?
> Also, is there a smarter/easier way of doing the stateless "migration"
> that I showed above?
>
> Regards,
> Andreas
>
> --
> >>>>>>>>>> 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 akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
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://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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
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