java.lang.Object
org.tentackle.persist.lock.DefaultLockManager
- All Implemented Interfaces:
LockManager
Default implementation of
LockManager.
The token locks are persisted in an extra table of DbTokenLocks in parallel to the token-lock columns
of the PDOs.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates the lock manager.
Enabled only if running within a server application. -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanupUserTokens(Db session, long userId) Removes all tokens for a given user.
The method is invoked when a user logs out or its session crashed.voidNotifies the lockmanager that a transaction has been committed.protected DbTokenLockcreateTokenLock(Db session) Creates a tokenlock persistent object.<T extends PersistentDomainObject<T>>
TokenLockgetLock(T pdo) Gets the token lock for a PDO.getLocks()Gets all token locks.getLocks(long userId) Gets the token locks for a user.voidinitialize(Db session) Initializes the lockmanager.
Called once at server startup to remove all locks.booleanReturns whether the lock manager is enabled.protected booleanisTokenLockToKeep(DbTokenLock dbTokenLock, DomainContext context) Returns whether a token lock should be kept on session cleanup or after server start.
The default implementation returns false.protected voidreloadLocks(Db session) Reloads locks from the database into the internal map.
There must be no transactions running!voidNotifies the lockmanager that a transaction has been rolled back.<T extends PersistentDomainObject<T>>
voidupdate(T pdo) Updates the lock token.
The method is invoked from within a transaction after the PDO has been persisted successfully.
-
Constructor Details
-
DefaultLockManager
public DefaultLockManager()Creates the lock manager.
Enabled only if running within a server application.
-
-
Method Details
-
isEnabled
public boolean isEnabled()Description copied from interface:LockManagerReturns whether the lock manager is enabled.- Specified by:
isEnabledin interfaceLockManager- Returns:
- true if server
-
cleanupUserTokens
Description copied from interface:LockManagerRemoves all tokens for a given user.
The method is invoked when a user logs out or its session crashed.- Specified by:
cleanupUserTokensin interfaceLockManager- Parameters:
session- the session to useuserId- the user id
-
initialize
Description copied from interface:LockManagerInitializes the lockmanager.
Called once at server startup to remove all locks.- Specified by:
initializein interfaceLockManager- Parameters:
session- the session to use
-
getLock
Description copied from interface:LockManagerGets the token lock for a PDO.- Specified by:
getLockin interfaceLockManager- Type Parameters:
T- the PDO type- Parameters:
pdo- the PDO- Returns:
- the token lock, null if PDO is not locked
-
getLocks
Description copied from interface:LockManagerGets the token locks for a user.- Specified by:
getLocksin interfaceLockManager- Parameters:
userId- the user's ID- Returns:
- the token locks
-
getLocks
Description copied from interface:LockManagerGets all token locks.- Specified by:
getLocksin interfaceLockManager- Returns:
- the token locks
-
update
Description copied from interface:LockManagerUpdates the lock token.
The method is invoked from within a transaction after the PDO has been persisted successfully.- Specified by:
updatein interfaceLockManager- Type Parameters:
T- the PDO type- Parameters:
pdo- the PDO
-
rollback
Description copied from interface:LockManagerNotifies the lockmanager that a transaction has been rolled back.- Specified by:
rollbackin interfaceLockManager- Parameters:
session- the sessiontxNumber- the unique transaction number
-
commit
Description copied from interface:LockManagerNotifies the lockmanager that a transaction has been committed.- Specified by:
commitin interfaceLockManager- Parameters:
session- the sessiontxNumber- the unique transaction number
-
createTokenLock
Creates a tokenlock persistent object.- Parameters:
session- the session- Returns:
- the PO
-
isTokenLockToKeep
Returns whether a token lock should be kept on session cleanup or after server start.
The default implementation returns false.- Parameters:
dbTokenLock- the token lockcontext- the domain context to use- Returns:
- true to keep it
-
reloadLocks
Reloads locks from the database into the internal map.
There must be no transactions running!The method is protected to allow application-specific lock managers to keep certain tokens on server startup after a crash, for example.
- Parameters:
session- the session
-