| 1 | package de.uka.ipd.sdq.scheduler.priority.boost; |
| 2 | |
| 3 | import de.uka.ipd.sdq.scheduler.priority.IPriority; |
| 4 | import de.uka.ipd.sdq.scheduler.priority.IPriorityBoost; |
| 5 | import de.uka.ipd.sdq.scheduler.priority.IPriorityUpdateStrategy; |
| 6 | import de.uka.ipd.sdq.scheduler.processes.impl.ProcessWithPriority; |
| 7 | |
| 8 | |
| 9 | |
| 10 | public class StaticPriorityBoost implements IPriorityBoost { |
| 11 | |
| 12 | private IPriorityUpdateStrategy update_strategy; |
| 13 | private int bonus; |
| 14 | private int penalty; |
| 15 | private boolean reset_timeslice; |
| 16 | |
| 17 | public StaticPriorityBoost(IPriorityUpdateStrategy update_strategy, |
| 18 | int bonus, int penalty, boolean reset_timeslice) { |
| 19 | super(); |
| 20 | this.update_strategy = update_strategy; |
| 21 | this.bonus = bonus; |
| 22 | this.penalty = penalty; |
| 23 | this.reset_timeslice = reset_timeslice; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | public void boost(ProcessWithPriority process) { |
| 28 | if (priorityChanges(process) || reset_timeslice){ |
| 29 | if (reset_timeslice){ |
| 30 | process.getTimeslice().halfReset(); |
| 31 | } else { |
| 32 | process.getTimeslice().updateTimeForBoosting(); |
| 33 | } |
| 34 | process.setToStaticPriorityWithBonus(bonus); |
| 35 | process.setPriorityUpdateStrategy(update_strategy); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | |
| 40 | public void punish(ProcessWithPriority process){ |
| 41 | process.getTimeslice().punish(penalty); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | |
| 46 | public boolean priorityChanges(ProcessWithPriority process){ |
| 47 | IPriority newPrio = process.getStaticPriority().addBonus(bonus); |
| 48 | return !newPrio.equals(process.getDynamicPriority()); |
| 49 | } |
| 50 | } |