Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e4fbbd6ac9c796d3dfafd5d29338b8275976bfdf
[simgrid.git] / examples / java / process / migration / Emigrant.java
1 /* Copyright (c) 2012-2018. 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 process.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 import org.simgrid.msg.HostNotFoundException;
14
15 public class Emigrant extends Process {
16   public Emigrant(String hostname, String name) throws HostNotFoundException {
17     super(hostname, name);
18   }
19
20   public void main(String[] args) throws MsgException {
21     Main.mutex.acquire();
22
23     Msg.info("I'll look for a new job on another machine where the grass is greener.");
24     migrate(Host.getByName("Boivin"));
25
26     Msg.info("Yeah, found something to do");
27     Task task = new Task("job", 98095000, 0);
28     task.execute();
29     waitFor(2);
30
31     Msg.info("Moving back to home after work");
32     migrate(Host.getByName("Jacquelin"));
33     migrate(Host.getByName("Boivin"));
34     waitFor(4);
35
36     Main.processToMigrate = this;
37     Main.mutex.release();
38     suspend();
39
40     Msg.info("I've been moved on this new host:" + getHost().getName());
41     Msg.info("Uh, nothing to do here. Stopping now");
42   }
43 }