|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
NodeLock.java | - | - | - | - |
|
1 | package org.jboss.cache.lock; | |
2 | ||
3 | import java.util.Set; | |
4 | ||
5 | ||
6 | /** | |
7 | * Interface for a lock for nodes. | |
8 | */ | |
9 | public interface NodeLock | |
10 | { | |
11 | ||
12 | public enum LockType | |
13 | { | |
14 | NONE, READ, WRITE | |
15 | } | |
16 | ||
17 | /** | |
18 | * Returns a copy of the reader lock owner in List. | |
19 | * Size is zero is not available. Note that this list | |
20 | * is synchronized. | |
21 | * | |
22 | * @return Set of readers | |
23 | */ | |
24 | Set getReaderOwners(); | |
25 | ||
26 | /** | |
27 | * Returns the writer lock owner object. Null if not available. | |
28 | * | |
29 | * @return Object owner | |
30 | */ | |
31 | Object getWriterOwner(); | |
32 | ||
33 | /** | |
34 | * Acquires a write lock with a timeout of <code>timeout</code> milliseconds. | |
35 | * Note that if the current owner owns a read lock, it will be upgraded | |
36 | * automatically. However, if upgrade fails, i.e., timeout, the read lock will | |
37 | * be released automatically. | |
38 | * | |
39 | * @param caller Can't be null. | |
40 | * @param timeout | |
41 | * @return boolean True if lock was acquired and was not held before, false if lock was held | |
42 | * @throws LockingException | |
43 | * @throws TimeoutException | |
44 | */ | |
45 | boolean acquireWriteLock(Object caller, long timeout) throws LockingException, TimeoutException, | |
46 | InterruptedException; | |
47 | ||
48 | /** | |
49 | * Acquires a read lock with a timeout period of <code>timeout</code> milliseconds. | |
50 | * | |
51 | * @param caller Can't be null. | |
52 | * @param timeout | |
53 | * @return boolean True if lock was acquired and was not held before, false if lock was held | |
54 | * @throws LockingException | |
55 | * @throws TimeoutException | |
56 | */ | |
57 | boolean acquireReadLock(Object caller, long timeout) throws LockingException, TimeoutException, InterruptedException; | |
58 | ||
59 | /** | |
60 | * Releases the lock held by the owner. | |
61 | * | |
62 | * @param caller Can't be null. | |
63 | */ | |
64 | void release(Object caller); | |
65 | ||
66 | /** | |
67 | * Releases all locks associated with this instance. | |
68 | */ | |
69 | void releaseAll(); | |
70 | ||
71 | /** | |
72 | * Releases all locks with this owner. | |
73 | */ | |
74 | void releaseAll(Object owner); | |
75 | ||
76 | /** | |
77 | * Check if there is a read lock. | |
78 | */ | |
79 | boolean isReadLocked(); | |
80 | ||
81 | /** | |
82 | * Check if there is a write lock. | |
83 | */ | |
84 | boolean isWriteLocked(); | |
85 | ||
86 | /** | |
87 | * Check if there is a read or write lock | |
88 | */ | |
89 | boolean isLocked(); | |
90 | ||
91 | /** | |
92 | * Returns true if the object is the lock owner. | |
93 | */ | |
94 | boolean isOwner(Object o); | |
95 | ||
96 | boolean acquire(Object caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException, | |
97 | InterruptedException; | |
98 | ||
99 | /** | |
100 | * Recursively acquire locks for this node and all subnodes. | |
101 | * @param caller lock owner | |
102 | * @param timeout time to wait | |
103 | * @param lock_type type of lock | |
104 | * @return locks acquired | |
105 | * @throws LockingException | |
106 | * @throws TimeoutException | |
107 | * @throws InterruptedException | |
108 | */ | |
109 | Set<NodeLock> acquireAll(Object caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException, | |
110 | InterruptedException; | |
111 | ||
112 | void printLockInfo(StringBuffer sb, int indent); | |
113 | ||
114 | } |
|