01: /*
02: * Created on 15-Jan-2006
03: */
04: package uk.org.ponder.rsf.state;
05:
06: import java.util.HashMap;
07: import java.util.Map;
08:
09: /**
10: * An application scope bean designed as a FlowLockGetter suitable for a
11: * single-JVM application. Will cooperate, for example, with
12: * {@link uk.org.ponder.rsf.flow.support.BasicScopedAlterationWrapper}
13: *
14: * @author Antranig Basman (amb26@ponder.org.uk)
15: *
16: */
17:
18: public class InMemoryLockGetter implements LockGetter {
19: // Maps flow tokens onto lock objects, while they are active
20: private Map flowlockmap = new HashMap();
21:
22: public Object getLock(String flowtoken) {
23: // It appears it is completely impossible to avoid a genuine lock here, so
24: // no point waiting for a Doug Lea solution. The point is that we expect
25: // that by far the most likely case is where there is a single lock, and
26: // the map is empty.
27: synchronized (flowlockmap) {
28: Object lock = flowlockmap.get(flowtoken);
29: if (lock == null) {
30: lock = new Object();
31: flowlockmap.put(flowtoken, lock);
32: }
33: return lock;
34: }
35: }
36:
37: public void returnLock(String flowtoken) {
38: flowlockmap.remove(flowtoken);
39: }
40: }
|