source: xssim/src/test/local/db/loader/RawResourcesReader.java @ 104

Revision 104, 1.4 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.local.db.loader;
2
3import java.text.ParseException;
4
5/**
6 *
7 * @author Marcin Krystek
8 *
9 */
10public class RawResourcesReader extends StatsReader {
11
12        public RawResourcesReader(StatsParser p) {
13                super(p);
14        }
15       
16        public String getResourceName(){
17                return this.values[0];
18        }
19       
20        public int getMemory(){
21                return getAsInt(1);
22        }
23       
24        public int getCpus(){
25                return getAsInt(2);
26        }
27       
28        public int getCpuSpeed(){
29                return getAsInt(3);
30        }
31       
32        public double getQueueLength(){
33                return getAsDouble(4);
34        }
35       
36        public Load[] getCpuLoad(){
37                String load = this.values[5];
38                if(load == null)
39                        return null;
40               
41                return prepareLoad(load);
42        }
43       
44        public Load[] getReservationLoad(){
45                String load = this.values[6];
46                if(load == null)
47                        return null;
48               
49                return prepareLoad(load);
50        }
51       
52        protected Load[] prepareLoad(String arg){
53               
54                String cpuList[] = arg.split(":");
55                Load result[] = new Load[cpuList.length];
56               
57                for(int i = 0; i < cpuList.length; i++){
58                        Load cpuLoad = new Load();
59                        String cpuDesc[] = cpuList[i].split(" ");
60                       
61                        cpuLoad.cpuName = cpuDesc[0];
62                        try {
63                                cpuLoad.value = this.format.parse(cpuDesc[1]).doubleValue();
64                        } catch (ParseException e) {
65                                e.printStackTrace();
66                                cpuLoad.value = -1.0;
67                        }
68                        result[i] = cpuLoad;
69                }
70                return result;
71        }
72       
73        public class Load{
74                public String cpuName;
75                public double value;
76               
77                public String toString(){
78                        return cpuName + " " + value;
79                }
80        }
81}
Note: See TracBrowser for help on using the repository browser.