Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LockManager |
|
| 1.0;1 |
1 | package org.apache.ojb.broker.locking; | |
2 | ||
3 | /* Copyright 2002-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | ||
19 | /** | |
20 | * This interface declares the functionality of the OJB locking-api for support of | |
21 | * pessimistic locking. | |
22 | * <p> | |
23 | * OJB allows to provide user defined implementations of this interface. | |
24 | * To activate a user defined LockManager implementation it must be configured in | |
25 | * the OJB.properties file. | |
26 | * </p> | |
27 | * <p> | |
28 | * All locks have to be reentrant, this means if you already have a lock for | |
29 | * writing and you try to acquire write access again you will not be blocked | |
30 | * by this first lock. | |
31 | * </p> | |
32 | * <p> | |
33 | * It's optional to support the <em>lockTimeout</em> and <em>blockTimeout</em> properties. | |
34 | * </p> | |
35 | * | |
36 | * @see LockManagerInMemoryImpl | |
37 | * @see LockManagerCommonsImpl | |
38 | * @version $Id: LockManager.java,v 1.1 2007-08-24 22:17:41 ewestfal Exp $ | |
39 | */ | |
40 | public interface LockManager extends IsolationLevels | |
41 | { | |
42 | /** | |
43 | * Default lock timeout value - set to 60000 ms. | |
44 | */ | |
45 | public final static long DEFAULT_LOCK_TIMEOUT = 60000; | |
46 | ||
47 | /** | |
48 | * Default lock wait time in millisecond - set to 1000 ms; | |
49 | */ | |
50 | public final static long DEFAULT_BLOCK_TIMEOUT = 1000; | |
51 | ||
52 | /** | |
53 | * The maximal time to wait for acquire a lock. | |
54 | * | |
55 | * @return | |
56 | */ | |
57 | public long getBlockTimeout(); | |
58 | ||
59 | /** | |
60 | * Set the maximal time to wait for acquire a lock in milliseconds. | |
61 | * All so called <em>non-blocking</em> implementation will ignore this setting. | |
62 | * | |
63 | * @param timeout The time to wait for acquire a lock. | |
64 | */ | |
65 | public void setBlockTimeout(long timeout); | |
66 | ||
67 | /** | |
68 | * Get the current used lock timeout value in milliseconds. | |
69 | * @return Current used locking timeout value in ms. | |
70 | */ | |
71 | public long getLockTimeout(); | |
72 | ||
73 | /** | |
74 | * Set the lock timeout value in milliseconds. If timeout was set to <em>-1</em> | |
75 | * the never will never timeout. | |
76 | * | |
77 | * @param timeout The lock timeout in <em>ms</em> of acquired read/write/upgrade locks. | |
78 | */ | |
79 | public void setLockTimeout(long timeout); | |
80 | ||
81 | /** | |
82 | * Returns info about the used lock manager implementation and the state | |
83 | * of the lock manager. | |
84 | */ | |
85 | public String getLockInfo(); | |
86 | ||
87 | /** | |
88 | * Acquires a readlock for lock key on resource object. | |
89 | * Returns true if successful, else false. | |
90 | * | |
91 | * @param key The owner key of the lock. | |
92 | * @param resourceId The resource to lock. | |
93 | * @param isolationLevel The isolation level of the lock. | |
94 | * @return <em>True</em> if the lock was successfully acquired. | |
95 | */ | |
96 | public boolean readLock(Object key, Object resourceId, int isolationLevel); | |
97 | ||
98 | /** | |
99 | * Acquires a write lock for lock key on resource object. | |
100 | * Returns true if successful, else false. | |
101 | * | |
102 | * @param key The owner key of the lock. | |
103 | * @param resourceId The resource to lock. | |
104 | * @param isolationLevel The isolation level of the lock. | |
105 | * @return <em>True</em> if the lock was successfully acquired. | |
106 | */ | |
107 | public boolean writeLock(Object key, Object resourceId, int isolationLevel); | |
108 | ||
109 | /** | |
110 | * Acquire an upgrade lock. | |
111 | * (Current implementations always acquire a write lock instead). | |
112 | * | |
113 | * @param key The owner key of the lock. | |
114 | * @param resourceId The resource to lock. | |
115 | * @param isolationLevel The isolation level of the lock. | |
116 | * @return <em>True</em> if the lock was successfully acquired. | |
117 | */ | |
118 | public boolean upgradeLock(Object key, Object resourceId, int isolationLevel); | |
119 | ||
120 | /** | |
121 | * Releases a lock for lock key on resource object. | |
122 | * Returns true if successful, else false. | |
123 | * | |
124 | * @param key The owner key of the lock. | |
125 | * @param resourceId The resource to release. | |
126 | * @return <em>True</em> if the lock was successfully released. | |
127 | */ | |
128 | public boolean releaseLock(Object key, Object resourceId); | |
129 | ||
130 | /** | |
131 | * Release all resource locks hold by the specified owner key. | |
132 | * | |
133 | * @param key The owner key to release all associated locks. | |
134 | */ | |
135 | public void releaseLocks(Object key); | |
136 | ||
137 | /** | |
138 | * Checks if there is a read lock for owner key on resource object. | |
139 | * Returns true if so, else false. | |
140 | * | |
141 | * @param key The owner key of the lock. | |
142 | * @param resourceId The resource to check. | |
143 | * @return <em>True</em> if the lock exists. | |
144 | */ | |
145 | public boolean hasRead(Object key, Object resourceId); | |
146 | ||
147 | /** | |
148 | * Checks if there is a write lock for lock key on resource object. | |
149 | * Returns true if so, else false. | |
150 | * | |
151 | * @param key The owner key of the lock. | |
152 | * @param resourceId The resource to check. | |
153 | * @return <em>True</em> if the lock exists. | |
154 | */ | |
155 | public boolean hasWrite(Object key, Object resourceId); | |
156 | ||
157 | /** | |
158 | * Checks if there is a upgrade lock for lock key on resource object. | |
159 | * Returns true if so, else false. | |
160 | * | |
161 | * @param key The owner key of the lock. | |
162 | * @param resourceId The resource to check. | |
163 | * @return <em>True</em> if the lock exists. | |
164 | */ | |
165 | public boolean hasUpgrade(Object key, Object resourceId); | |
166 | } |