1 | package de.uka.ipd.sdq.scheduler.resources.passive; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | |
6 | import de.uka.ipd.sdq.scheduler.IPassiveResource; |
7 | import de.uka.ipd.sdq.scheduler.ISchedulableProcess; |
8 | import de.uka.ipd.sdq.scheduler.sensors.IPassiveResourceSensor; |
9 | |
10 | /** |
11 | * Provides observer functionality to passive resources. Normally this |
12 | * functionality would reside in an (abstract) super class, but for passive |
13 | * resources there is no such class that all resources inherit. |
14 | * |
15 | * @author Philipp Merkle |
16 | * |
17 | */ |
18 | public class PassiveResourceObservee { |
19 | |
20 | private List<IPassiveResourceSensor> observers; |
21 | |
22 | public PassiveResourceObservee() { |
23 | observers = new ArrayList<IPassiveResourceSensor>(); |
24 | } |
25 | |
26 | /** |
27 | * Notifies observers that the resource has been requested. |
28 | */ |
29 | public void fireRequest(ISchedulableProcess process, int num) { |
30 | for (IPassiveResourceSensor o : observers) { |
31 | o.request(process, num); |
32 | } |
33 | } |
34 | |
35 | /** |
36 | * Notifies observers that the resource has been acquired. |
37 | */ |
38 | public void fireAquire(ISchedulableProcess process, int num) { |
39 | for (IPassiveResourceSensor o : observers) { |
40 | o.acquire(process, num); |
41 | } |
42 | } |
43 | |
44 | /** |
45 | * Notifies observers that the resource has been released. |
46 | */ |
47 | public void fireRelease(ISchedulableProcess process, int num) { |
48 | for (IPassiveResourceSensor o : observers) { |
49 | o.release(process, num); |
50 | } |
51 | } |
52 | |
53 | /** |
54 | * @see IPassiveResource#addObserver(IPassiveResourceSensor) |
55 | */ |
56 | public void addObserver(IPassiveResourceSensor observer) { |
57 | observers.add(observer); |
58 | } |
59 | |
60 | /** |
61 | * @see IPassiveResource#removeObserver(IPassiveResourceSensor) |
62 | */ |
63 | public void removeObserver(IPassiveResourceSensor observer) { |
64 | observers.remove(observer); |
65 | } |
66 | |
67 | } |