Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
194630675e80578589411fea2024dfaa2ae07d89
[simgrid.git] / examples / java / migration / Emigrant.java
1 /* Copyright (c) 2012-2014, 2016. The SimGrid Team.
2  * 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 import org.simgrid.msg.Msg;
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Task;
11 import org.simgrid.msg.Process;
12 import org.simgrid.msg.MsgException;
13
14 public class Emigrant extends Process {
15   public Emigrant(Host host, String name, String[]args) {
16     super(host,name,args);
17   }
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 }