Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add example of java cpu model
[simgrid.git] / examples / java / surfCpuModel / CpuConstantModel.java
1 package surfCpuModel;
2
3 import org.simgrid.surf.*;
4 import org.simgrid.msg.Msg;
5 import java.util.List;
6 import java.util.ArrayList;
7
8 public class CpuConstantModel extends CpuModel {
9
10   private List<CpuConstant> cpus = new ArrayList<CpuConstant>();
11   private List<CpuConstantAction> actions = new ArrayList<CpuConstantAction>();
12
13   public CpuConstantModel() {
14     super("Cpu Constant");
15     Msg.info("Initialize Cpu Constant Model");
16   }
17
18   public Cpu createResource(String name, double[] power_peak, int pstate, double power_scale, TmgrTrace power_trace, int core, ResourceState state_initial, TmgrTrace state_trace, XbtDict cpu_properties) {
19     Msg.info("Create Resource Name: "+name);
20     CpuConstant res = new CpuConstant(this, name, cpu_properties, actions, 1, 1000, 1000);
21     cpus.add(res);
22     Surf.setCpu(name, res);
23     return res;
24   }
25
26   public void setState(ResourceState state) {
27     Msg.info("setState");
28   }
29
30   public double shareResources(double now) {
31     Msg.info("shareResource of "+cpus.size()+" cpu and "+actions.size()+" actions");
32     return now+1;
33   }
34
35   public void updateActionsState(double now, double delta) {
36     Msg.info("updateActionState of "+cpus.size()+" cpu and "+actions.size()+" actions");
37   }
38
39   public void addTraces() {
40   }
41
42 public class CpuConstant extends Cpu {
43   private List<CpuConstantAction> actions;
44
45   public CpuConstant(CpuConstantModel model, String name, XbtDict props,
46                      List<CpuConstantAction> actions,
47                      int core, double powerPeak, double powerScale) {
48     super(model, name, props, core, powerPeak, powerScale);
49     this.actions = actions;
50   }
51
52   public CpuAction execute(double size) {
53     CpuConstantAction res = new CpuConstantAction(getModel(), size, false);
54     Msg.info("Execute action of size "+size);
55     actions.add(res);
56     return res;
57   }
58
59   public CpuAction sleep(double duration) {
60     CpuConstantAction res = new CpuConstantAction(getModel(), duration, false);
61     Msg.info("Sleep action of duration "+duration);
62     actions.add(res);
63     return res;
64   }
65
66   public ResourceState getState(){
67     return ResourceState.SURF_RESOURCE_ON;
68   }
69 }
70
71 public class CpuConstantAction extends CpuAction {
72   public CpuConstantAction(Model model, double cost, boolean failed) {
73     super(model, cost, failed);
74   }
75 }
76 }
77