Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add migration example
[simgrid.git] / examples / migration / Emigrant.java
1 /*
2  * 2012. The SimGrid Team. All rights reserved. 
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. 
6  */
7 package migration;
8
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.MsgException;
12 import org.simgrid.msg.Task;
13 import org.simgrid.msg.Process;
14
15 public class Emigrant extends Process {
16         public Emigrant(Host host, String name, String[]args) {
17                 super(host,name,args);
18         }
19         public void main(String[] args) throws MsgException {           
20                 Migration.mutex.acquire();
21                 
22                 Msg.info("I'll look for a new job on another machine where the grass is greener.");
23                 migrate(Host.getByName("Boivin"));
24                 
25                 Msg.info("Yeah, found something to do");
26                 Task task = new Task("job", 98095000, 0);
27                 task.execute();
28                 waitFor(2);
29                 
30                 Msg.info("Moving back to home after work");
31                 migrate(Host.getByName("Jacquelin"));
32                 migrate(Host.getByName("Boivin"));
33                 waitFor(4);
34                 
35                 Migration.processToMigrate = this;
36                 Migration.mutex.release();              
37                 suspend();
38                         
39                 Msg.info("I've been moved on this new host:" + getHost().getName());
40                 Msg.info("Uh, nothing to do here. Stopping now");
41         }
42 }