Class ObjectLockManager
- java.lang.Object
-
- com.github.toolarium.common.object.ObjectLockManager
-
- All Implemented Interfaces:
IObjectLockManager,java.io.Serializable
public class ObjectLockManager extends java.lang.Object implements IObjectLockManager, java.io.Serializable
Defines the object lock manager- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ObjectLockManager()ConstructorObjectLockManager(java.lang.Integer lockSize, java.lang.Long unlockTimeout)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup()Cleanup too old unlock elementsvoidcleanupAfterUnlock(boolean cleanupAfterUnlock)Define if the cleanup of unlock timeout should be forced after an unlockStatisticCountergetIgnoreLockStatistic()Get the ignore object lock statisticStatisticCountergetLockStatistic()Get the object lock statisticlonggetNumberOfLockSizeReached()Get the count of how many times the max lock size was reachedStatisticCountergetUnlockStatistic()Get the object unlock statisticprotected voidinit()Initialize<L extends java.io.Serializable>
java.util.List<L>lock(java.util.List<L> theObjectLockList)Locks a list of objects inside the same JVM.voidreleaseResource()Release all object locks and resourcesIObjectLockManagersetObjectLockSize(java.lang.Integer lockSize)Sets the size of the object lockIObjectLockManagersetUnlockTimeout(java.lang.Long unlockTimeout)Sets the unlock timeout which defines how long an element can't be blocked again after an unlockjava.lang.StringtoString()<L extends java.io.Serializable>
java.util.List<L>unlock(java.util.List<L> theObjectLockList)Unlock a list of objects inside the same JVM.
-
-
-
Constructor Detail
-
ObjectLockManager
public ObjectLockManager()
Constructor
-
ObjectLockManager
public ObjectLockManager(java.lang.Integer lockSize, java.lang.Long unlockTimeout)Constructor- Parameters:
lockSize- defines the lock sizeunlockTimeout- the timeout after unlock an object is still not be able to lock
-
-
Method Detail
-
setObjectLockSize
public IObjectLockManager setObjectLockSize(java.lang.Integer lockSize) throws java.lang.IllegalArgumentException
Description copied from interface:IObjectLockManagerSets the size of the object lock- Specified by:
setObjectLockSizein interfaceIObjectLockManager- Parameters:
lockSize- the object lock size (positive number) or null- Returns:
- the instance
- Throws:
java.lang.IllegalArgumentException- See Also:
IObjectLockManager.setObjectLockSize(Integer)
-
setUnlockTimeout
public IObjectLockManager setUnlockTimeout(java.lang.Long unlockTimeout)
Description copied from interface:IObjectLockManagerSets the unlock timeout which defines how long an element can't be blocked again after an unlock- Specified by:
setUnlockTimeoutin interfaceIObjectLockManager- Parameters:
unlockTimeout- the unlock timeout (positive number) or null- Returns:
- the instance
- See Also:
IObjectLockManager.setUnlockTimeout(java.lang.Long)
-
lock
public <L extends java.io.Serializable> java.util.List<L> lock(java.util.List<L> theObjectLockList)
Description copied from interface:IObjectLockManagerLocks a list of objects inside the same JVM.- Specified by:
lockin interfaceIObjectLockManager- Type Parameters:
L- the object lock type- Parameters:
theObjectLockList- the list of objects to lock- Returns:
- Returns only the successfully locked objects. It returns in all cases a list but it doesn't throws any exceptions!
- See Also:
IObjectLockManager.lock(java.util.List)
-
unlock
public <L extends java.io.Serializable> java.util.List<L> unlock(java.util.List<L> theObjectLockList)
Description copied from interface:IObjectLockManagerUnlock a list of objects inside the same JVM.- Specified by:
unlockin interfaceIObjectLockManager- Type Parameters:
L- the object lock type- Parameters:
theObjectLockList- the list of objects to unlock- Returns:
- the list of objects to unlock
- See Also:
IObjectLockManager.unlock(java.util.List)
-
cleanupAfterUnlock
public void cleanupAfterUnlock(boolean cleanupAfterUnlock)
Define if the cleanup of unlock timeout should be forced after an unlock- Parameters:
cleanupAfterUnlock- true or false
-
cleanup
public void cleanup()
Cleanup too old unlock elements
-
releaseResource
public void releaseResource()
Description copied from interface:IObjectLockManagerRelease all object locks and resources- Specified by:
releaseResourcein interfaceIObjectLockManager- See Also:
IObjectLockManager.releaseResource()
-
getLockStatistic
public StatisticCounter getLockStatistic()
Description copied from interface:IObjectLockManagerGet the object lock statistic- Specified by:
getLockStatisticin interfaceIObjectLockManager- Returns:
- the object lock statistic
- See Also:
IObjectLockManager.getLockStatistic()
-
getUnlockStatistic
public StatisticCounter getUnlockStatistic()
Description copied from interface:IObjectLockManagerGet the object unlock statistic- Specified by:
getUnlockStatisticin interfaceIObjectLockManager- Returns:
- the object unlock statistic
- See Also:
IObjectLockManager.getUnlockStatistic()
-
getIgnoreLockStatistic
public StatisticCounter getIgnoreLockStatistic()
Description copied from interface:IObjectLockManagerGet the ignore object lock statistic- Specified by:
getIgnoreLockStatisticin interfaceIObjectLockManager- Returns:
- the ignore object lock statistic
- See Also:
IObjectLockManager.getIgnoreLockStatistic()
-
getNumberOfLockSizeReached
public long getNumberOfLockSizeReached()
Description copied from interface:IObjectLockManagerGet the count of how many times the max lock size was reached- Specified by:
getNumberOfLockSizeReachedin interfaceIObjectLockManager- Returns:
- the count of how many times the max lock size was reached
- See Also:
IObjectLockManager.getNumberOfLockSizeReached()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- See Also:
Object.toString()
-
init
protected void init()
Initialize
-
-