Class ObjectLockManager
java.lang.Object
com.github.toolarium.common.object.ObjectLockManager
- All Implemented Interfaces:
IObjectLockManager,Serializable
Defines the object lock manager
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructorObjectLockManager(Integer lockSize, Long unlockTimeout) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()Cleanup too old unlock elementsvoidcleanupAfterUnlock(boolean cleanupAfterUnlock) Define if the cleanup of unlock timeout should be forced after an unlockGet the statistics of locks that could not be obtained because they are already locked.Get the object lock statistic (the number of lock elements)longGet the count of how many times the max lock size was reachedGet the statistics of locks that could not be obtained because of the unlock timeout.protected voidinit()Initialize<L extends Serializable>
List<L> Locks a list of objects inside the same JVM.voidRelease all object locks and resourcessetObjectLockSize(Integer lockSize) Sets the size of the object locksetUnlockTimeout(Long unlockTimeout) Sets the unlock timeout which defines how long an element can't be locked again after an unlocktoString()<L extends Serializable>
List<L> Unlock a list of objects inside the same JVM.
-
Constructor Details
-
ObjectLockManager
public ObjectLockManager()Constructor -
ObjectLockManager
Constructor- Parameters:
lockSize- defines the lock sizeunlockTimeout- the timeout after unlock an object is still not be able to lock
-
-
Method Details
-
setObjectLockSize
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:
IllegalArgumentException- See Also:
-
setUnlockTimeout
Description copied from interface:IObjectLockManagerSets the unlock timeout which defines how long an element can't be locked again after an unlock- Specified by:
setUnlockTimeoutin interfaceIObjectLockManager- Parameters:
unlockTimeout- the unlock timeout (positive number) or null- Returns:
- the instance
- See Also:
-
lock
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:
-
unlock
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:
-
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:
-
getLockStatistic
Description copied from interface:IObjectLockManagerGet the object lock statistic (the number of lock elements)- Specified by:
getLockStatisticin interfaceIObjectLockManager- Returns:
- the object lock statistic
- See Also:
-
getUnlockStatistic
Description copied from interface:IObjectLockManagerGet the statistics of locks that could not be obtained because of the unlock timeout.- Specified by:
getUnlockStatisticin interfaceIObjectLockManager- Returns:
- the object unlock statistic
- See Also:
-
getIgnoreLockStatistic
Description copied from interface:IObjectLockManagerGet the statistics of locks that could not be obtained because they are already locked.- Specified by:
getIgnoreLockStatisticin interfaceIObjectLockManager- Returns:
- the ignore object lock statistic
- See Also:
-
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:
-
toString
-
init
protected void init()Initialize
-