|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.spif.StoreChain | +--net.sf.spif.StoreLocker
Include in a store chain to get pessimistic locking of all objects fecthed for writing.
Objects will be locked for a configurable time.
This class is backed by a Locker
.
Usually, locking should be ties to a certain identity,
so Bob
may lock one object and
Alice another.
If the call ending up here is entering the server though
the store sesison bean, this is taken care of. Otherwise
you'll have to explicitly make identities available to Spif
and the locker by calling
ThreadContext.setPrincipalName(java.lang.String)
, usually with
the value of sessionContext.getCallerPrincipal().getName().
Field Summary |
Fields inherited from class net.sf.spif.StoreChain |
chained |
Constructor Summary | |
StoreLocker()
Creates a store locked with a default lock timeout (30 minutes) |
|
StoreLocker(long timeout)
Creates a store locked with a lock timeout |
Method Summary | |
void |
clear()
Removes all locks |
java.lang.Object |
get(Id id,
boolean writeable)
Returns an objects, but locks it first if it writeable is true. |
Id |
put(Id id,
java.lang.Object object)
Puts a changed or new object into the store. |
boolean |
remove(Id id)
Removes any held lock before forwarding, |
void |
unlock(Id id)
Unlocks a previously locked object |
Methods inherited from class net.sf.spif.StoreChain |
equals, getChained, getChained, getChained, hashCode, setChained |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public StoreLocker()
public StoreLocker(long timeout)
Method Detail |
public java.lang.Object get(Id id, boolean writeable)
Returns an objects, but locks it first if it writeable is true.
The locker identity is the principal name of the requester,
obtained from ThreadContext
. Thus the thread context must
have a principal set for this to work. The StoreSessionBean
does this, if you get to the server by another bean, make sure
it sets the principal to threadcontext.
get
in class StoreChain
id
- the id of the object to return
LockedException
- if the objects was allready
locked by somebody elsepublic Id put(Id id, java.lang.Object object)
put
in class StoreChain
id
- the id of the object to put. May be nullobject
- the object to put. May be null
LockedException
- if the object is locked by somebody elsepublic boolean remove(Id id)
remove
in class StoreChain
id
- the id of the object to remove
LockedException
- if locked by somebody elsepublic void unlock(Id id)
public void clear()
clear
in class StoreChain
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |