package schedframe.resources.units; import schedframe.scheduling.utils.ResourceParameterName; public class Processors extends ResourceUnit { protected int total; protected int used; protected int peSpeed; protected Processors(){ super(ResourceParameterName.CPUCOUNT); this.peSpeed = 1; } public Processors(int total, int used, int avgSpeed){ this(); this.total = total; this.used = used; this.peSpeed = avgSpeed; } public Processors(String resId, int total, int used) { super(resId, ResourceParameterName.CPUCOUNT); this.total = total; this.used = used; this.peSpeed = 1; } public void setProcessorSpeed(int speed) { this.peSpeed = speed; } public int getProcessorSpeed(){ return this.peSpeed; } public int getFreeAmount() { return this.total - this.used; } public int getUsedAmount(){ return this.used; } public int getAmount(){ return this.total; } public void setUsedAmount(int amount) { this.used = amount; } public void reset(){ this.used = 0; } public ResourceUnit toDiscrete(){ throw new UnsupportedOperationException(); } /** * Compares processing power of the free processors, which is calculated as product * of {@link #getAmount()} * {@link #getProcessorSpeed()} * Returns a negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object */ public int compareTo(ResourceUnit o) { if(o instanceof Processors){ Processors p = (Processors) o; int p_power = p.getAmount() * p.getProcessorSpeed(); int power = this.getAmount() * this.getProcessorSpeed(); if(power < p_power) return -1; if(power > p_power) return 1; return 0; } else { throw new ClassCastException(); } } public boolean equals(Object o){ if(o instanceof Processors){ if(!super.equals(o)) return false; Processors p = (Processors) o; if(p.getProcessorSpeed() != this.getProcessorSpeed()) return false; return true; } else { return false; } } }