1 | package de.uka.ipd.sdq.scheduler.loaddistribution.balancers; |
2 | |
3 | import java.util.Hashtable; |
4 | |
5 | import de.uka.ipd.sdq.scheduler.loaddistribution.ILoadBalancer; |
6 | import de.uka.ipd.sdq.scheduler.queueing.strategies.MultipleQueuesStrategy; |
7 | import de.uka.ipd.sdq.scheduler.resources.IResourceInstance; |
8 | |
9 | public abstract class AbstractLoadBalancer implements ILoadBalancer { |
10 | |
11 | /** |
12 | * Minimum time that needs to pass between two load balancing attempts |
13 | */ |
14 | protected double balancing_interval; |
15 | |
16 | /** |
17 | * Holder of the runqueues that need to be balanced. |
18 | */ |
19 | protected MultipleQueuesStrategy queue_holder; |
20 | |
21 | /** |
22 | * Determines the order how movable processes are returned. If true, the |
23 | * priority of the processes is increasing, otherwise decreasing. |
24 | */ |
25 | protected boolean prio_increasing; |
26 | |
27 | /** |
28 | * Determines the order how movable processes are returned. If true, the |
29 | * first processes are returned in the same order of the queue, otherwise |
30 | * they are returned in reverse order. |
31 | */ |
32 | protected boolean queue_ascending; |
33 | |
34 | protected Hashtable<IResourceInstance, Double> last_balanced; |
35 | |
36 | |
37 | |
38 | /** |
39 | * Creates a new instance of a load balancer. |
40 | * |
41 | * @param balancing_interval |
42 | * Minimum time that needs to pass between two executions of the |
43 | * load balancer. |
44 | * |
45 | * @param prio_increasing |
46 | * Determines the order how movable processes are returned. If |
47 | * true, the priority of the processes is increasing, otherwise |
48 | * decreasing. |
49 | * |
50 | * @param queue_ascending |
51 | * Determines the order how movable processes are returned. If |
52 | * true, the first processes are returned in the same order of |
53 | * the queue, otherwise they are returned in reverse order. |
54 | */ |
55 | protected AbstractLoadBalancer(double balancing_interval, |
56 | boolean prio_increasing, |
57 | boolean queue_ascending) { |
58 | super(); |
59 | this.balancing_interval = balancing_interval; |
60 | this.prio_increasing = prio_increasing; |
61 | this.queue_ascending = queue_ascending; |
62 | this.queue_holder = null; |
63 | this.last_balanced = new Hashtable<IResourceInstance, Double>(); |
64 | } |
65 | |
66 | |
67 | protected int load(IResourceInstance instance) { |
68 | return queue_holder.getRunQueueFor(instance).getCurrentLoad(); |
69 | } |
70 | |
71 | public void setQueueHolder(MultipleQueuesStrategy queue_holder) { |
72 | this.queue_holder = queue_holder; |
73 | for (IResourceInstance instance : queue_holder.getResourceInstances()) { |
74 | this.last_balanced.put(instance, 0.0); |
75 | } |
76 | } |
77 | |
78 | |
79 | } |