1 | package de.uka.ipd.sdq.prototype.framework.strategies; |
2 | |
3 | import java.util.concurrent.Semaphore; |
4 | |
5 | import org.apache.log4j.Logger; |
6 | |
7 | public class PassiveResource { |
8 | |
9 | private static Logger logger = |
10 | Logger.getLogger(PassiveResource.class.getName()); |
11 | |
12 | private Semaphore semaphore; |
13 | private String type; |
14 | |
15 | public PassiveResource(int capacity, String type){ |
16 | this.semaphore = new Semaphore(capacity, true); |
17 | this.type = type; |
18 | } |
19 | |
20 | public void acquire(){ |
21 | logger.debug("Acquiring "+type); |
22 | this.semaphore.acquireUninterruptibly(); |
23 | logger.debug(type+" aquired"); |
24 | } |
25 | |
26 | public void release(){ |
27 | this.semaphore.release(); |
28 | logger.debug(type+" released"); |
29 | } |
30 | |
31 | public String getType() { |
32 | return type; |
33 | } |
34 | |
35 | } |