Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d3ac758b2ca527c21b19fe62fa01fd9512f2602b
[simgrid.git] / examples / java / cloud / migration / Daemon.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 package cloud.migration;
7
8 import org.simgrid.msg.*;
9 import org.simgrid.msg.Process;
10
11 public class Daemon extends Process {
12         private Task currentTask;
13     public Daemon(VM vm, int load) {
14                 super((Host)vm,"Daemon");
15        currentTask = new Task(this.getHost().getName()+"-daemon-0", this.getHost().getSpeed()*100, 0);
16     }
17     public void main(String[] args) throws MsgException {
18         int i = 1;
19         while(!Main.isEndOfTest()) {
20             // TODO the binding is not yet available
21             try {
22                 currentTask.execute();
23             } catch (HostFailureException e) {
24                 e.printStackTrace();
25             } catch (TaskCancelledException e) {
26                 System.out.println("task cancelled");
27                 suspend(); // Suspend the process
28             }
29             currentTask = new Task(this.getHost().getName()+"-daemon-"+(i++), this.getHost().getSpeed()*100, 0);
30             Msg.info(currentTask.getName());
31         }
32     }
33
34     public double getRemaining(){
35         return this.currentTask.getRemainingDuration();
36     }
37     }