Revision 1606,
981 bytes
checked in by wojtekp, 8 years ago
(diff) |
|
-
Property svn:mime-type set to
text/plain
|
Line | |
---|
1 | package test.testSOP; |
---|
2 | |
---|
3 | import java.util.Comparator; |
---|
4 | |
---|
5 | import schedframe.resources.computing.Node; |
---|
6 | |
---|
7 | public class ComparatorHostHighestLoadFirst implements Comparator<Node>{ |
---|
8 | private float getMostLoadedResource(Node n) { |
---|
9 | float memLoad = 0, cpuLoad; |
---|
10 | try { |
---|
11 | memLoad = (float)1 - (float)n.getFreeMemory() / (float)n.getTotalMemory(); |
---|
12 | } catch (NoSuchFieldException e) { |
---|
13 | // TODO Auto-generated catch block |
---|
14 | e.printStackTrace(); |
---|
15 | } |
---|
16 | cpuLoad = (float)1 - (float)n.getFreeProcessorsNumber() / (float)n.getProcessorsNumber(); |
---|
17 | // log.debug("GetMostLoadedResource node "+n.getName()+": "+cpuLoad+" -- "+memLoad); |
---|
18 | if (cpuLoad > memLoad) { |
---|
19 | return cpuLoad; |
---|
20 | } |
---|
21 | else { |
---|
22 | return memLoad; |
---|
23 | } |
---|
24 | } |
---|
25 | @Override |
---|
26 | public int compare(Node node1, Node node2) { |
---|
27 | if (getMostLoadedResource(node1) < getMostLoadedResource(node2)) |
---|
28 | return 1; |
---|
29 | else if (getMostLoadedResource(node1) > getMostLoadedResource(node2)) |
---|
30 | return -1; |
---|
31 | else |
---|
32 | return 0; |
---|
33 | } |
---|
34 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.