Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / java / SleepHostOff / SleepHostOff.java
1 /* Copyright (c) 2014. 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 SleepHostOff;
8
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11
12 class Sleeper extends Process {
13   public Sleeper(Host host, String name, String[] args) {
14     super(host,name,args);
15   }
16   public void main(String[] args) {
17     while (true) {
18       Msg.info("I'm not dead");
19       try {
20         Process.sleep(10);
21       } catch (HostFailureException e) {
22         Msg.info("catch HostException: "+e.getLocalizedMessage());
23         break; //Break is needed to finalize the endless loop 
24       }
25     }
26   }
27 }
28
29 class TestRunner extends Process {
30   public TestRunner(Host host, String name, String[] args) {
31     super(host,name,args);
32   }
33
34   public void main(String[] strings) throws MsgException {
35     Host host = Host.getByName("Tremblay");
36
37     Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
38     Msg.info("Test sleep: Create a process on "+host.getName()+" that simply make periodic sleep, turn off "
39              +host.getName());
40     new Sleeper(host, "Sleeper", null).start();
41
42     waitFor(0.02);
43     Msg.info("Stop "+host.getName());
44     host.off();
45     Msg.info(host.getName()+" has been stopped");
46     waitFor(0.3);
47     Msg.info("Test sleep seems ok, cool! (number of Process : " + Process.getCount() 
48              + ", it should be 1 (i.e. the Test one))");
49   }
50 }
51
52 public class SleepHostOff {
53   public static void main(String[] args) throws Exception {
54     Msg.init(args);
55
56     if (args.length < 1) {
57       Msg.info("Usage: java -cp simgrid.jar:. sleep_host_off.SleepHostOff <platform.xml>");
58       System.exit(1);
59     }
60
61     Msg.createEnvironment(args[0]);
62
63     new TestRunner(Host.getByName("Fafard"), "TestRunner", null).start();
64
65     Msg.run();
66   }
67 }