Class SessionLock
java.lang.Object
de.aristaflow.adept2.util.locking.ReentrantLock<SessionToken>
de.aristaflow.adept2.base.sessionmanagement.SessionLock
Represents a reentrant read/write lock or exclusive lock based on session
token.
This session lock supports the consideration of subsessions. They may either be considered as equal to a parent session or not with regard to a lock. If you do not want to treat subsessions as equal, attend particularly to deadlocks!
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classALockCountManagercounting session tokens with an equality based on the UUID returned by aFunctionprovided by subclasses.static classALockCountManagercounting session tokens with an equality based on child session IDs.static classALockCountManagerconsidering session tokens and their subsessions (but not vice versa!) as equal.static classALockCountManagercounting session tokens with an equality based on their UUIDs (of the corresponding top-level session token).static classALockCountManagerconsidering session tokens and their subsessions (but not vice versa!) as equal.Nested classes/interfaces inherited from class de.aristaflow.adept2.util.locking.ReentrantLock
ReentrantLock.Lock, ReentrantLock.ReadLock, ReentrantLock.WriteLock -
Field Summary
Fields inherited from class de.aristaflow.adept2.util.locking.ReentrantLock
logger, notification, readLock, writeLock -
Constructor Summary
ConstructorsConstructorDescriptionSessionLock(LockCountManager<SessionToken> writeLockCountManager, LockCountManager<SessionToken> readLockCountManager, LockNotification<SessionToken> notification, Logger logger) Creates either a new exclusive lock or a new read/write-lock and using theLockCountManagerfor counting locks as well as comparing objects.SessionLock(LockCountManager<SessionToken> lockCountManager, LockNotification<SessionToken> notification, Logger logger) Creates a new exclusive lock using the designatedLockCountManagerfor counting locks as well as comparing objects.SessionLock(LockCountManager<SessionToken> lockCountManager, Logger logger) Creates a new exclusive lock using the designatedLockCountManagerfor counting locks as well as comparing objects.SessionLock(Class<? extends LockCountManager<SessionToken>> lockCountManager, boolean exclusive, LockNotification<SessionToken> notification, Logger logger) Creates either a new exclusive lock or a new read/write-lock and using the designatedLockCountManagerfor counting locks as well as comparing objects.SessionLock(Class<? extends LockCountManager<SessionToken>> lockCountManager, boolean exclusive, Logger logger) Creates either a new exclusive lock or a new read/write-lock and using the designatedLockCountManagerfor counting locks as well as comparing sessions. -
Method Summary
Modifier and TypeMethodDescriptionprotected static SessionTokengetNearestCommonAncestor(SessionToken first, SessionToken second) Gets the session token that is the nearest common ancestor of the designated session tokens.protected static booleanisAncestorOf(UUID ancestorId, int ancestorLevel, SessionToken session) Gets whether the designated ID belongs to a session token that is an ancestor of the designated session token.Methods inherited from class de.aristaflow.adept2.util.locking.ReentrantLock
invalidate, isReadLocked, isWriteLocked, readLock, writeLock
-
Constructor Details
-
SessionLock
public SessionLock(Class<? extends LockCountManager<SessionToken>> lockCountManager, boolean exclusive, Logger logger) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException Creates either a new exclusive lock or a new read/write-lock and using the designatedLockCountManagerfor counting locks as well as comparing sessions.- Parameters:
lockCountManager- The manager counting locks for sessions. The provided class needs an accessible (public) constructor without parameters.exclusive- Whether to create an exclusive lock or a read/write-lock.logger- The logger for log messages.- Throws:
NoSuchMethodException- If the designated lock count manager has no constructor without parameters, aNouSuchMethodExceptionwill be thrown.InstantiationException- If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, anInstantiationExceptionwill be thrown.IllegalAccessException- If the designated lock count manager class or its constructor is not accessible, anIllegalAccessExceptionwill be thrown.InvocationTargetException- If the designated lock count manager throws an exception, this will be wrapped by anInvocationTargetException.
-
SessionLock
public SessionLock(Class<? extends LockCountManager<SessionToken>> lockCountManager, boolean exclusive, LockNotification<SessionToken> notification, Logger logger) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException Creates either a new exclusive lock or a new read/write-lock and using the designatedLockCountManagerfor counting locks as well as comparing objects. The designated notification will be used for notifying a successful lock or unlock while locking and unlocking, that is, the notification will be atomically with respect to locking/unlocking.- Parameters:
lockCountManager- The manager counting locks for objects. The provided class needs an accessible (public) constructor without parameters.exclusive- Whether to create an exclusive lock or a read/write-lock.notification- The notification to call directly but atomically after locking and unlocking. If this isnull, no notification will be sent.logger- The logger for log messages.- Throws:
NoSuchMethodException- If the designated lock count manager has no constructor without parameters, aNouSuchMethodExceptionwill be thrown.InstantiationException- If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, anInstantiationExceptionwill be thrown.InvocationTargetException- If the designated lock count manager throws an exception, this will be wrapped by anInvocationTargetException.IllegalAccessException
-
SessionLock
Creates a new exclusive lock using the designatedLockCountManagerfor counting locks as well as comparing objects.- Parameters:
lockCountManager- The manager counting locks for objects.logger- The logger for log messages.
-
SessionLock
public SessionLock(LockCountManager<SessionToken> lockCountManager, LockNotification<SessionToken> notification, Logger logger) Creates a new exclusive lock using the designatedLockCountManagerfor counting locks as well as comparing objects. The designated notification will be used for notifying a successful lock or unlock while locking and unlocking, that is, the notification will be atomically with respect to locking/unlocking.- Parameters:
lockCountManager- The manager counting locks for objects.notification- The notification to call directly but atomically after locking and unlocking. If this isnull, no notification will be sent.logger- The logger for log messages.
-
SessionLock
public SessionLock(LockCountManager<SessionToken> writeLockCountManager, LockCountManager<SessionToken> readLockCountManager, LockNotification<SessionToken> notification, Logger logger) Creates either a new exclusive lock or a new read/write-lock and using theLockCountManagerfor counting locks as well as comparing objects. If there is no lock count manager for the read lock or it equals the lock count manager for the write lock, an exclusive lock will be created, otherwise this will be read/write-lock.
The designated notification will be used for notifying a successful lock or unlock while locking and unlocking, that is, the notification will be atomically with respect to locking/unlocking.- Parameters:
writeLockCountManager- The manager counting write locks for objects.readLockCountManager- The manager counting read locks for objects. If this isnullor equals thewriteLockCountManager, an exclusive lock will be created.notification- The notification to call directly but atomically after locking and unlocking. If this isnull, no notification will be sent.logger- The logger for log messages.
-
-
Method Details
-
isAncestorOf
Gets whether the designated ID belongs to a session token that is an ancestor of the designated session token.- Parameters:
ancestorId- The ID which to check for whether it belongs to an ancestor session token.ancestorLevel- The level of the ancestor.session- The session token to check for whether it is a descendant of the session token with the designated (child) ID.- Returns:
- Whether the designated ID belongs to a session token that is an ancestor of the designated session token.
-
getNearestCommonAncestor
Gets the session token that is the nearest common ancestor of the designated session tokens. This is the session token with the highest child level of which both session tokens are descendants of. If no such session token exists,nullwill be returned.- Parameters:
first- The first session token to find the nearest common ancestor.second- The second session token to find the nearest common ancestor.- Returns:
- The nearest common ancestor session token of the designated session token or
nullif no such session token exists.
-