1 package org.apache.fulcrum.yaafi.framework.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.avalon.framework.logger.Logger;
23 import org.apache.fulcrum.yaafi.framework.locking.AvalonLoggerFacade;
24
25
26 /**
27 * A simple lock manager supporting read locks and write locks. The main
28 * intention is to shield the application from the implementation details.
29 *
30 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
31 */
32 public class ReadWriteLock
33 {
34 /** Read/Write lock to synchronize acess to services */
35 private final org.apache.fulcrum.yaafi.framework.locking.ReadWriteLock lock;
36
37 /**
38 * Constructor
39 *
40 * @param name the name of the lock
41 * @param logger the logger to be used
42 */
43 public ReadWriteLock( String name, Logger logger )
44 {
45 this.lock = new org.apache.fulcrum.yaafi.framework.locking.ReadWriteLock(
46 name,
47 new AvalonLoggerFacade(logger)
48 );
49 }
50
51 /**
52 * @return a read lock
53 */
54 public Object getReadLock(String ownerId)
55 throws InterruptedException
56 {
57 this.lock.acquireRead(ownerId,0);
58 return this;
59 }
60
61 /**
62 * @return a write lock
63 */
64 public Object getWriteLock(String ownerId)
65 throws InterruptedException
66 {
67 this.lock.acquireWrite(ownerId,0);
68 return this;
69 }
70
71 /**
72 * releases the lock
73 * @param lock the lock
74 */
75 public void releaseLock(Object lock, String ownerId)
76 {
77 this.lock.release(ownerId);
78 }
79 }