KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > lock > NodeLock


1 package org.jboss.cache.lock;
2
3 import java.util.Set JavaDoc;
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 JavaDoc getReaderOwners();
25
26    /**
27     * Returns the writer lock owner object. Null if not available.
28     *
29     * @return Object owner
30     */

31    Object JavaDoc 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 JavaDoc caller, long timeout) throws LockingException, TimeoutException,
46          InterruptedException JavaDoc;
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 JavaDoc caller, long timeout) throws LockingException, TimeoutException, InterruptedException JavaDoc;
58
59    /**
60     * Releases the lock held by the owner.
61     *
62     * @param caller Can't be null.
63     */

64    void release(Object JavaDoc 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 JavaDoc 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 JavaDoc o);
95
96    boolean acquire(Object JavaDoc caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException,
97          InterruptedException JavaDoc;
98
99    Set JavaDoc acquireAll(Object JavaDoc caller, long timeout, NodeLock.LockType lock_type) throws LockingException, TimeoutException,
100          InterruptedException JavaDoc;
101
102    void printLockInfo(StringBuffer JavaDoc sb, int indent);
103
104 }
Popular Tags