Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
peersimgrid release 1.0
[simgrid.git] / contrib / psg / src / psgsim / PSGProcessCycle.java
1 package psgsim;
2
3 import java.util.Map.Entry;
4
5 import org.simgrid.msg.Host;
6 import peersim.cdsim.CDProtocol;
7 import peersim.core.Node;
8 import peersim.core.Protocol;
9
10 /**
11  * This class handle an event of type NextCycleEvent, received on the protocol
12  * identified by a pid among all CDProtocols defined in the
13  * {@link PSGPlatform#cdProtocolsStepMap} collection.
14  * <p>
15  * It executes the nextCyle method associated to this protocol.
16  * 
17  * @author Khaled Baati 27/10/2014
18  * @version version 1.1
19  */
20 public class PSGProcessCycle {
21
22         /**
23          * Executes the nextCycle method of the CDprotocol with the appropriate
24          * parameters, and schedules the next call using {@link PSGSimulator#add}.
25          * 
26          * @param host
27          *            the host on which this component is run
28          * @param name
29          *            the host's name
30          * @param delay
31          *            the start time
32          * @param event
33          *            the actual event
34          * @param pid
35          *            the protocol identifier
36          */
37         public static void nextCycle(Host host, String name, double delay,
38                         Object event, int pid) {
39                 CDProtocol cdp = null;
40                 Node node = NodeHost.getNode(host);
41                 cdp = (CDProtocol) node.getProtocol(pid);
42                 cdp.nextCycle(node, pid);
43                 PSGTransport.flush();
44                 for (Entry<Protocol, Double> entry : PSGPlatform.cdProtocolsStepMap
45                                 .entrySet()) {
46                         Double step = entry.getValue();
47                         for (Entry<Protocol, Integer> p : PSGPlatform.protocolsPidsMap
48                                         .entrySet()) {
49                                 if (p.getValue() == pid) {
50                                         break;
51                                 }
52                         }
53                         if (PSGPlatform.getTime() <= PSGPlatform.getDuration() && host.isOn()) {
54                                 PSGSimulator.add(PSGPlatform.sgToPsTime(step), event, node, pid);
55                         }
56                 }
57         }
58
59 }