Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[simgrid.git] / contrib / psg / src / psgsim / PSGProcessLauncher.java
1 package psgsim;
2
3 import org.simgrid.msg.Host;
4 import org.simgrid.msg.MsgException;
5
6 import peersim.core.Node;
7 import peersim.edsim.EDProtocol;
8 import peersim.edsim.NextCycleEvent;
9
10 /**
11  * This class extends {@link org.simgrid.msg.Process}, it creates a process for
12  * each event added in {@link PSGSimulator#add}.
13  * <p>
14  * This class performs to launch the appropriate call according to the type of
15  * the event;
16  * <p>
17  * - A NextCycleEvent: the event will be delivered to the
18  * {@link PSGProcessCycle} for treatment.
19  * <p>
20  * - Otherwise the event is delivered to the destination protocol, that must
21  * implement {@link EDProtocol}, and the processEvent method is executed.
22  * 
23  * @author Khaled Baati 12/11/2014
24  * @version version 1.1
25  */
26 public class PSGProcessLauncher extends org.simgrid.msg.Process {
27         private EDProtocol prot = null;
28         private int pid;
29         private double delay;
30         private Object event;
31         private Host host;
32
33         /**
34          * Constructs a new process from the name of a host and with the associated
35          * parameters
36          * 
37          * @param host
38          *            the local host
39          * @param name
40          *            the host's name
41          * @param delay
42          *            the start time of the process
43          * @param event
44          *            the event added to the simulator
45          * @param pid
46          *            the protocol identifier
47          */
48         public PSGProcessLauncher(Host host, String name, double delay, Object event,
49                         int pid) {
50                 super(host, name, null, delay, -1);
51                 this.host = host;
52                 this.pid = pid;
53                 this.event = event;
54                 this.delay = delay;
55         }
56
57         public PSGProcessLauncher(Host host, String name, String[] args) {
58
59         }
60
61         @Override
62         public void main(String[] args) throws MsgException {
63                 Node node = NodeHost.getNode(host);
64                 if (event instanceof NextCycleEvent) {
65                         PSGProcessCycle.nextCycle(Host.currentHost(), host.getName(),
66                                         delay, event, pid);
67                 } else {
68                         prot = (EDProtocol) node.getProtocol(pid);
69                         prot.processEvent(node, pid, event);
70                         PSGTransport.flush();
71                 }
72                 waitFor(500);
73         }
74 }