I am trying to develop a mechanism to know which machine can handle a user job (by providing his Requirements) for now I wrote this method but it is a Round robin, I am trying to modify it to a best-fit algorithm can anybody give me tips about how should I begin?
Expand|Select|Wrap|Line Numbers
- public static String canDo(Resources userReq,Hashtable hash){
- //getResourceInfo() is a method that store the machine name
- //and thier resources(cpu,memory,disk) in a hashtable
- Hashtable resourceInfo = connectData.getResourcesInfo();
- Enumeration en = resourceInfo.keys();
- String status ="";
- String machineName;
- Resources machineRec;
- while(en.hasMoreElements()) {
- machineName = (String)en.nextElement();
- status = "the following machine has been allocated to you: "+machineName;
- //resourc
- machineRec = (Resources)resourceInfo.get(machineName);
- if(machineRec.getCpu().getCpuIdle()>=userReq.getCpu().getCpuIdle())
- if(machineRec.getMemory().getFreeMemory()>=userReq.getMemory().getFreeMemory())
- if(machineRec.getDisk().getFreeSpace()>=userReq.getDisk().getFreeSpace()){
- break;
- }
- }
- return status;
- }