Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the tesh of one last command
[simgrid.git] / teshsuite / java / sleep_host_off / 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 sleep_host_off;
8
9 import org.simgrid.msg.*;
10 import org.simgrid.msg.Process;
11 import org.simgrid.trace.Trace;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Random;
16
17 public class SleepHostOff extends Process{
18   public static Host jupiter = null;
19
20   public SleepHostOff(Host host, String name, String[]args) {
21     super(host,name,args);
22   }
23
24   public void main(String[] strings) throws MsgException {
25
26     try {
27       jupiter = Host.getByName("Jupiter");
28     } catch (HostNotFoundException e) {
29       e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
30     }
31
32     Msg.info("**** **** **** ***** ***** Test Sleep ***** ***** **** **** ****");
33     Msg.info("Test sleep: Create a process on Jupiter, the process simply make periodic sleep, turn off Jupiter");
34     new Process(jupiter, "sleep", null) {
35       public void main(String[] args) {
36         while (true) {
37           Msg.info("I'm not dead");
38           try {
39             Process.sleep(10);
40           } catch (HostFailureException e) {
41             Msg.info("catch HostException: "+e.getLocalizedMessage());
42             break; //Break is needed to finalize the endless loop 
43           }
44         }
45       }
46     }.start();
47
48     Process.sleep(20);
49     Msg.info("Stop Jupiter");
50     jupiter.off();
51     Msg.info("Jupiter has been stopped");
52     Process.sleep(300);
53     Msg.info("Test sleep seems ok, cool !(number of Process : " + Process.getCount() + ", it should be 1 (i.e. the Test one))\n");
54   }
55 }