Class SessionLock
- java.lang.Object
-
- de.aristaflow.adept2.util.locking.ReentrantLock<SessionToken>
-
- de.aristaflow.adept2.base.sessionmanagement.SessionLock
-
public class SessionLock extends ReentrantLock<SessionToken>
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:
ReentrantReadWriteLock
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SessionLock.AbstractLockCount
ALockCountManager
counting session tokens with an equality based on the UUID returned by aFunction
provided by subclasses.static class
SessionLock.ChildSessionIDLockCount
ALockCountManager
counting session tokens with an equality based on child session IDs.static class
SessionLock.DownwardSubtreeLockCount
ALockCountManager
considering session tokens and their subsessions (but not vice versa!)static class
SessionLock.SessionIdLockCount
ALockCountManager
counting session tokens with an equality based on their UUIDs (of the corresponding top-level session token).static class
SessionLock.SessionTreePathLockCount
Deprecated.This does not work as intended.static class
SessionLock.SubsessionLockCount
Deprecated.This does not work as intended.static class
SessionLock.UpwardSubtreeLockCount
ALockCountManager
considering session tokens and their subsessions (but not vice versa!)static class
SessionLock.UUIDLockCount
Deprecated.UseSessionLock.SessionIdLockCount
instead.-
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
Constructors Constructor Description 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 theLockCountManager
for counting locks as well as comparing objects.SessionLock(LockCountManager<SessionToken> lockCountManager, LockNotification<SessionToken> notification, Logger logger)
Creates a new exclusive lock using the designatedLockCountManager
for counting locks as well as comparing objects.SessionLock(LockCountManager<SessionToken> lockCountManager, Logger logger)
Creates a new exclusive lock using the designatedLockCountManager
for 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 designatedLockCountManager
for 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 designatedLockCountManager
for counting locks as well as comparing sessions.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static SessionToken
getNearestCommonAncestor(SessionToken first, SessionToken second)
Gets the session token that is the nearest common ancestor of the designated session tokens.protected static boolean
isAncestorOf(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 Detail
-
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 designatedLockCountManager
for 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, aNouSuchMethodException
will be thrown.InstantiationException
- If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, anInstantiationException
will be thrown.IllegalAccessException
- If the designated lock count manager class or its constructor is not accessible, anIllegalAccessException
will 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 designatedLockCountManager
for 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, aNouSuchMethodException
will be thrown.InstantiationException
- If the designated lock count manager class cannot be instantiated or does not have a parameterless constructor, anInstantiationException
will be thrown.InvocationTargetException
- If the designated lock count manager throws an exception, this will be wrapped by anInvocationTargetException
.IllegalAccessException
-
SessionLock
public SessionLock(LockCountManager<SessionToken> lockCountManager, Logger logger)
Creates a new exclusive lock using the designatedLockCountManager
for 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 designatedLockCountManager
for 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 theLockCountManager
for 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 isnull
or 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 Detail
-
isAncestorOf
protected static boolean isAncestorOf(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.- 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
protected static SessionToken getNearestCommonAncestor(SessionToken first, SessionToken second)
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,null
will 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
null
if no such session token exists.
-
-