KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > lock > DummyLockRegistry


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.lock;
14
15 import java.util.HashMap JavaDoc;
16
17 import org.jahia.services.usermanager.JahiaUser;
18
19 /**
20  *
21  * This is a dummy lock service that is used to never lock anything.
22  * It can be used in place of default lock service as long as it is not completely working well.
23  *
24  * @version 1.0
25  */

26 public class DummyLockRegistry extends LockService {
27
28     /**
29      * Default constructor
30      */

31     private DummyLockRegistry() {
32         logger.debug("Lock registry has been instanciated");
33     }
34
35     private static DummyLockRegistry lockRegistryInstance;
36
37     private static org.apache.log4j.Logger logger =
38         org.apache.log4j.Logger.getLogger(DummyLockRegistry.class);
39
40     /**
41      * Return the unique registry instance. If the instance does not exist,
42      * a new instance is created.
43      *
44      * @return The unique lock registry instance.
45      */

46     public synchronized static DummyLockRegistry getInstance() {
47         if (lockRegistryInstance == null) {
48             lockRegistryInstance = new DummyLockRegistry();
49         }
50         return lockRegistryInstance;
51     }
52
53     /**
54      * Acquire a lock if the appropriate prerequisites are complete.
55      *
56      * @param lockKey The lock key identifying the lock.
57      * @param owner The lock owner
58      * @param lockID The lock ID
59      * @param timeout The period in second during which the lock is valid. For a
60      * non expiration time lock use the constant NO_EXPIRATION_TIME.
61      * @return True if the lock was acquired, false otherwise.
62      */

63     public synchronized boolean acquire(LockKey lockKey, JahiaUser owner,
64                                         String JavaDoc lockID, int timeout) {
65         return true;
66     }
67
68     /**
69      * Test if a lock is acquireable if the appropriate prerequisites are
70      * complete.
71      *
72      * @param lockKey The lock key identifying the lock.
73      * @param owner The lock owner
74      * @param lockID The lock ID
75      * @return true if the lock is acquireable, false otherwise.
76      */

77     public synchronized boolean isAcquireable(LockKey lockKey, JahiaUser owner,
78                                               String JavaDoc lockID) {
79         return true;
80     }
81
82     /**
83      * Reserve a lock with a defined expiration delay after which the lock is
84      * acquired to the user.
85      *
86      * @param lockKey The lock key identifying the lock.
87      * @param owner The lock owner
88      * @param lockID The lock identifier.
89      * @param timeout Lock time out.
90      * @param delay Lock delay...
91      * @return True if the lock can be reserved, false otherwise.
92      *
93      * @todo To implement
94      */

95     public synchronized boolean reserve(LockKey lockKey, JahiaUser owner,
96                                         String JavaDoc lockID, int timeout, int delay) {
97         return false;
98     }
99
100     /**
101      * Release the acquired lock. The lock should be in the correct context.
102      *
103      * @param lockKey The lock key identifying the lock.
104      * @param owner The lock owner
105      * @param lockID The lock identifier.
106      */

107     public synchronized void release(LockKey lockKey, JahiaUser owner,
108                                      String JavaDoc lockID) {
109     }
110
111     /**
112      * Return a lock information from a lock stored in the registry.
113      *
114      * @param lockKey The lock key identifying the lock.
115      * @return The lock attributes
116      */

117     public synchronized HashMap JavaDoc getInfo(LockKey lockKey) {
118         HashMap JavaDoc lockInfo = new HashMap JavaDoc();
119         return lockInfo;
120     }
121
122     /**
123      * Get the remaining time from a lock stored in the registry.
124      *
125      * @param lockKey The lock key identifying the lock.
126      * @return The lock tremaining time in second.
127      */

128     public synchronized Long JavaDoc getTimeRemaining(LockKey lockKey) {
129         return new Long JavaDoc(0);
130     }
131
132     /**
133      * Change the lock context meaning that it can be stolen. Actually we admit
134      * that only user with administration priviliges has the right to perform
135      * this operation.
136      *
137      * @param lockKey The lock key identifying the lock.
138      * @param newOwner The new lock owner.
139      * @param lockID The new lock identifier.
140      */

141     public synchronized void steal(LockKey lockKey, JahiaUser newOwner,
142                                    String JavaDoc lockID) {
143     }
144
145     /**
146      * Force to remove the lock from the registry meaning that it can be broken
147      * (nuked). Actually we admit that only user with administration priviliges
148      * has the right to perform this operation.
149      *
150      * @param lockKey The lock key identifying the lock.
151      * @param owner The lock owner.
152      * @param lockID The lock identifier.
153      *
154      * Sorry, should be called "break" but it is a reserved word ;)
155      */

156     public synchronized void nuke(LockKey lockKey, JahiaUser owner, String JavaDoc lockID) {
157     }
158
159     /**
160      * Return is the lock has been stolen or not.
161      *
162      * @param lockKey The lock key identifying the lock.
163      * @return True is the lock has benn stolen, false otherwise.
164      */

165     public boolean isStealed(LockKey lockKey) {
166         return true;
167     }
168
169     /**
170      * Return if a lock has already been acquired.
171      *
172      * @param lockKey The lock key identifying the lock.
173      * @return True if the lock has already been acquired, false otherwise.
174      */

175     public synchronized boolean isAlreadyAcquired(LockKey lockKey) {
176         return false;
177     }
178
179     /**
180      * Define if a lock has been stolen in a specified context.
181      *
182      * @param lockKey The lock key identifying the lock.
183      * @param owner The lock owner.
184      * @param lockID The lock identifier.
185      * @return True if the lock has been stolen in the context, false otherwise.
186      */

187     public synchronized boolean isStealedInContext(LockKey lockKey, JahiaUser owner, String JavaDoc lockID) {
188         return false;
189     }
190
191     /**
192      * Define if a lock has already been acquired in a specified context.
193      *
194      * @param lockKey The lock key identifying the lock.
195      * @param owner The lock owner.
196      * @param lockID The lock identifier.
197      * @return True if the lock has been already acquired in the context,
198      * false otherwise.
199      */

200     public synchronized boolean isAlreadyAcquiredInContext(LockKey lockKey,
201             JahiaUser owner, String JavaDoc lockID) {
202         return false;
203     }
204
205     /**
206      * Define if a lock can be released or not.
207      *
208      * @param lockKey The lock key identifying the lock.
209      * @param owner The lock owner.
210      * @param lockID The lock identifier.
211      * @return True if the lock can be released, false otherwise.
212      */

213     public synchronized boolean canRelease(LockKey lockKey, JahiaUser owner,
214                                            String JavaDoc lockID) {
215         return true;
216     }
217
218     /**
219      * Define is the Jahia user has admin rights on a specified lock.
220      *
221      * @param lockKey The lock key identifying the lock.
222      * @param owner The lock owner.
223      * @return True if the user has admin rights, false otherwise.
224      */

225     public synchronized boolean hasAdminRights(LockKey lockKey, JahiaUser owner) {
226         return true;
227     }
228
229     /**
230      * Purge all locks and lock prerequisites from memory and database,
231      * effectively freeing all the objects. This is a powerful operation and
232      * must be used with care as it might cause problems when people already
233      * have open popups.
234      */

235     public void purgeLocks() {
236     }
237
238 }
Popular Tags