Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
peersimgrid release 1.0
[simgrid.git] / contrib / psg / src / peersim / rangesim / ProcessManager.java
1 package peersim.rangesim;
2
3 import java.util.*;
4
5 /**
6  * This thread is used to kill forked processes in the case of an abnormal
7  * termination of the Java virtual machine (for example, due to a signal).
8  */
9 public class ProcessManager extends Thread
10 {
11
12 /** The threads that must be killed */
13 private List<ProcessHandler> threads;
14
15 public ProcessManager()
16 {
17         threads = Collections.synchronizedList(new ArrayList<ProcessHandler>());
18 }
19
20 public void addThread(ProcessHandler p)
21 {
22         threads.add(p);
23 }
24
25 /**
26  * Assumes that the process manager
27  */
28 public void joinAll()
29 {
30         int i=0;
31         while (i < threads.size()) {
32                 try {
33                         threads.get(i).join();
34                         i++;
35                 } catch (InterruptedException e) {
36                 }
37         }
38 }
39
40
41 /**
42  * Kill the child process.
43  */
44 public void run()
45 {
46         System.err.println("Terminating simulation.");
47         for (int i=0; i < threads.size(); i++) {
48                 if (threads.get(i) != null)
49                         threads.get(i).doStop();
50         }
51 }
52
53 }