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 voidaddPropertyChangeListener(java.beans.PropertyChangeListener pcl)Register to listen toDFLockable.PROP_LOCKEDproperty change.voidcheckLock(DFLock testedLock)Checks whether the lock belongs to this lockable.booleanisLocked()Is a valid lock held by someone already?booleanisLockedForever()Is this lockable constantly locked? This can be used for lockables which are in readonly mode (e.g.DFLockobtainLock(java.lang.String reason)Obtains the lock; fails withAlreadyLockedExceptionif the object is already locked.voidremovePropertyChangeListener(java.beans.PropertyChangeListener pcl)Unregister to listen toDFLockable.PROP_LOCKEDproperty change.
-
-
-
Method Detail
-
obtainLock
public DFLock obtainLock(java.lang.String reason) throws AlreadyLockedException
Description copied from interface:DFLockableObtains the lock; fails withAlreadyLockedExceptionif the object is already locked.- Specified by:
obtainLockin 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 ofDFLockbefore and this lock is still active
-
isLocked
public boolean isLocked()
Description copied from interface:DFLockableIs a valid lock held by someone already?- Specified by:
isLockedin interfaceDFLockable- Returns:
trueif locked
-
isLockedForever
public boolean isLockedForever()
Description copied from interface:DFLockableIs 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()returnstrueduring 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_LOCKEDproperty on thisDFLockable, because it will be never fired.- Specified by:
isLockedForeverin interfaceDFLockable- Returns:
trueif "forever locked"
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Description copied from interface:DFLockableRegister to listen toDFLockable.PROP_LOCKEDproperty change.- Specified by:
addPropertyChangeListenerin interfaceDFLockable- Parameters:
pcl- The PropertyChangeListener to register
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Description copied from interface:DFLockableUnregister to listen toDFLockable.PROP_LOCKEDproperty change.- Specified by:
removePropertyChangeListenerin interfaceDFLockable- Parameters:
pcl- Th PropertyChangeListener to unregister
-
checkLock
public void checkLock(DFLock testedLock)
Description copied from interface:DFLockableChecks whether the lock belongs to this lockable.- Specified by:
checkLockin interfaceDFLockable- Parameters:
testedLock- The lock to check
-
-