1 package locklib;
2
3 import ensure.Ensure;
4
5 /**
6 * Request for a lock. A lock request contains the type of lock requested and
7 * the holder requesting the lock.
8 * @param <LockType> the type of lock
9 */
10 public class LockRequest<LockType> {
11 /**
12 * Type of lock requested.
13 */
14 private LockType m_type;
15
16 /**
17 * Holder requesting the lock.
18 */
19 private Object m_holder;
20
21 /**
22 * Creates a new lock request.
23 * @param type the type of lock
24 * @param h the holder requesting the lock
25 */
26 public LockRequest(LockType type, Object h) {
27 Ensure.not_null(type, "type == null");
28 Ensure.not_null(h, "h == null");
29
30 m_type = type;
31 m_holder = h;
32 }
33
34 /**
35 * Obtains the type of lock.
36 * @return the type of lock
37 */
38 public LockType type() {
39 return m_type;
40 }
41
42 /**
43 * Obtains the holder of the lock.
44 * @return the holder of the lock
45 */
46 public Object holder() {
47 return m_holder;
48 }
49
50 @Override
51 public String toString() {
52 return "LockRequest[type=" + m_type + ", holder=" + m_holder + "]";
53 }
54 }