KickJava   Java API By Example, From Geeks To Geeks.

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


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.JahiaService;
18 import org.jahia.services.usermanager.JahiaUser;
19
20 public abstract class LockService extends JahiaService {
21
22     /**
23      * Acquire a lock if the appropriate prerequisites are complete.
24      *
25      * @param lockKey The lock key identifying the lock.
26      * @param owner The lock owner
27      * @param lockID The lock ID
28      * @param timeout The period in second during which the lock is valid. For a
29      * non expiration time lock use the constant NO_EXPIRATION_TIME.
30      * @return True if the lock was acquired, false otherwise.
31      */

32     public abstract boolean acquire (LockKey lockKey, JahiaUser owner,
33                                      String JavaDoc lockID, int timeout);
34
35     /**
36      * Test if a lock is acquireable if the appropriate prerequisites are
37      * complete.
38      *
39      * @param lockKey The lock key identifying the lock.
40      * @param owner The lock owner
41      * @param lockID The lock ID
42      * @return true if the lock is acquireable, false otherwise.
43      */

44     public abstract boolean isAcquireable (LockKey lockKey, JahiaUser owner,
45                                            String JavaDoc lockID);
46
47     /**
48      * Reserve a lock with a defined expiration delay after which the lock is
49      * acquired to the user.
50      *
51      * @param lockKey The lock key identifying the lock.
52      * @param owner The lock owner
53      * @param lockID The lock identifier.
54      * @param timeout Lock time out.
55      * @param delay Lock delay...
56      * @return True if the lock can be reserved, false otherwise.
57      *
58      * @todo To implement
59      */

60     public abstract boolean reserve(LockKey lockKey, JahiaUser owner,
61                                         String JavaDoc lockID, int timeout, int delay);
62
63     /**
64      * Release the acquired lock. The lock should be in the correct context.
65      *
66      * @param lockKey The lock key identifying the lock.
67      * @param owner The lock owner
68      * @param lockID The lock identifier.
69      */

70     public abstract void release(LockKey lockKey, JahiaUser owner,
71                                      String JavaDoc lockID);
72
73     /**
74      * Return a lock information from a lock stored in the registry.
75      *
76      * @param lockKey The lock key identifying the lock.
77      * @return The lock attributes
78      */

79     public abstract HashMap JavaDoc getInfo(LockKey lockKey);
80
81     /**
82      * Get the remaining time from a lock stored in the registry.
83      *
84      * @param lockKey The lock key identifying the lock.
85      * @return The lock tremaining time in second.
86      */

87     public abstract Long JavaDoc getTimeRemaining(LockKey lockKey);
88
89     /**
90      * Change the lock context meaning that it can be stolen. Actually we admit
91      * that only user with administration priviliges has the right to perform
92      * this operation.
93      *
94      * @param lockKey The lock key identifying the lock.
95      * @param newOwner The new lock owner.
96      * @param lockID The new lock identifier.
97      */

98     public abstract void steal(LockKey lockKey, JahiaUser newOwner,
99                                    String JavaDoc lockID);
100
101     /**
102      * Force to remove the lock from the registry meaning that it can be broken
103      * (nuked). Actually we admit that only user with administration priviliges
104      * has the right to perform this operation.
105      *
106      * @param lockKey The lock key identifying the lock.
107      * @param owner The lock owner.
108      * @param lockID The lock identifier.
109      *
110      * Sorry, should be called "break" but it is a reserved word ;)
111      */

112     public abstract void nuke(LockKey lockKey, JahiaUser owner, String JavaDoc lockID);
113
114     /**
115      * Return is the lock has been stolen or not.
116      *
117      * @param lockKey The lock key identifying the lock.
118      * @return True is the lock has benn stolen, false otherwise.
119      */

120     public abstract boolean isStealed(LockKey lockKey);
121
122     /**
123      * Return if a lock has already been acquired.
124      *
125      * @param lockKey The lock key identifying the lock.
126      * @return True if the lock has already been acquired, false otherwise.
127      */

128     public abstract boolean isAlreadyAcquired(LockKey lockKey);
129
130     /**
131      * Define if a lock has been stolen in a specified context.
132      *
133      * @param lockKey The lock key identifying the lock.
134      * @param owner The lock owner.
135      * @param lockID The lock identifier.
136      * @return True if the lock has been stolen in the context, false otherwise.
137      */

138     public abstract boolean isStealedInContext(LockKey lockKey, JahiaUser owner, String JavaDoc lockID);
139
140     /**
141      * Define if a lock has already been acquired in a specified context.
142      *
143      * @param lockKey The lock key identifying the lock.
144      * @param owner The lock owner.
145      * @param lockID The lock identifier.
146      * @return True if the lock has been already acquired in the context,
147      * false otherwise.
148      */

149     public abstract boolean isAlreadyAcquiredInContext(LockKey lockKey,
150             JahiaUser owner, String JavaDoc lockID);
151
152     /**
153      * Define if a lock can be released or not.
154      *
155      * @param lockKey The lock key identifying the lock.
156      * @param owner The lock owner.
157      * @param lockID The lock identifier.
158      * @return True if the lock can be released, false otherwise.
159      */

160     public abstract boolean canRelease(LockKey lockKey, JahiaUser owner,
161                                            String JavaDoc lockID);
162
163     /**
164      * Define is the Jahia user has admin rights on a specified lock.
165      *
166      * @param lockKey The lock key identifying the lock.
167      * @param owner The lock owner.
168      * @return True if the user has admin rights, false otherwise.
169      */

170     public abstract boolean hasAdminRights(LockKey lockKey, JahiaUser owner);
171
172     /**
173      * Purge all locks and lock prerequisites from memory and database,
174      * effectively freeing all the objects. This is a powerful operation and
175      * must be used with care as it might cause problems when people already
176      * have open popups.
177      */

178     public abstract void purgeLocks();
179
180 }
Popular Tags