Package com.im.commons.progress
Class SimpleLockable
- java.lang.Object
-
- com.im.commons.progress.SimpleLockable
-
- All Implemented Interfaces:
DFLockable
public final class SimpleLockable extends java.lang.Object implements DFLockable
Lockable with minimal functionality to cover test-cases needs.
-
-
Field Summary
-
Fields inherited from interface com.im.commons.progress.DFLockable
PROP_LOCKED
-
-
Constructor Summary
Constructors Constructor Description SimpleLockable()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Register to listen toDFLockable.PROP_LOCKED
property change.void
checkLock(DFLock testedLock)
Checks whether the lock belongs to this lockable.boolean
isLocked()
Is a valid lock held by someone already?boolean
isLockedForever()
Is this lockable constantly locked? This can be used for lockables which are in readonly mode (e.g.DFLock
obtainLock(java.lang.String reason)
Obtains the lock; fails withAlreadyLockedException
if the object is already locked.void
removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Unregister to listen toDFLockable.PROP_LOCKED
property change.
-
-
-
Method Detail
-
obtainLock
public DFLock obtainLock(java.lang.String reason) throws AlreadyLockedException
Description copied from interface:DFLockable
Obtains the lock; fails withAlreadyLockedException
if the object is already locked.- Specified by:
obtainLock
in interfaceDFLockable
- Parameters:
reason
- The localized string explaining the operation or reason for locking. May benull
.- Returns:
- The lock, if one can be obtained. Never returns
null
, throws exception instead. - Throws:
AlreadyLockedException
- if lockable provided another instance ofDFLock
before and this lock is still active
-
isLocked
public boolean isLocked()
Description copied from interface:DFLockable
Is a valid lock held by someone already?- Specified by:
isLocked
in interfaceDFLockable
- Returns:
true
if locked
-
isLockedForever
public boolean isLockedForever()
Description copied from interface:DFLockable
Is this lockable constantly locked? This can be used for lockables which are in readonly mode (e.g. when you log in as a user without appropriate access rights). If this method returnstrue
, it means thatDFLockable.isLocked()
returnstrue
during whole life time of this object and will never change. Lockable which is "forever locked" will never change this status to unlocked during one session. It also means that you don't need to listen toDFLockable.PROP_LOCKED
property on thisDFLockable
, because it will be never fired.- Specified by:
isLockedForever
in interfaceDFLockable
- Returns:
true
if "forever locked"
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Description copied from interface:DFLockable
Register to listen toDFLockable.PROP_LOCKED
property change.- Specified by:
addPropertyChangeListener
in interfaceDFLockable
- Parameters:
pcl
- The PropertyChangeListener to register
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Description copied from interface:DFLockable
Unregister to listen toDFLockable.PROP_LOCKED
property change.- Specified by:
removePropertyChangeListener
in interfaceDFLockable
- Parameters:
pcl
- Th PropertyChangeListener to unregister
-
checkLock
public void checkLock(DFLock testedLock)
Description copied from interface:DFLockable
Checks whether the lock belongs to this lockable.- Specified by:
checkLock
in interfaceDFLockable
- Parameters:
testedLock
- The lock to check
-
-