- java.lang.Object
-
- org.tentackle.persist.lock.DefaultLockManager
-
- All Implemented Interfaces:
LockManager
@Service(LockManager.class) public class DefaultLockManager extends Object implements LockManager
Default implementation ofLockManager.The token locks are persisted in an extra table of
DbTokenLocks in parallel to the editedBy-tokens of the PDOs.
-
-
Constructor Summary
Constructors Constructor Description DefaultLockManager()Creates the lock manager.
Enabled only if running within a server application.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanupUserTokens(Db session, long userId)Removes all tokens for a given user.
The method is invoked when a user logs out or its session crashed.voidcommit(Db session, long txNumber)Notifies 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.Collection<TokenLock>getLocks()Gets all token locks.Collection<TokenLock>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.booleanisEnabled()Returns whether the lock manager is enabled.protected voidreloadLocks(Db session)Reloads locks from the database into the internal map.
There must be no transactions running!protected voidremove(DbTokenLock lock, DomainContext context)Removes a token lock from the lock table and the PDO.voidrollback(Db session, long txNumber)Notifies 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.
-
-
-
Method Detail
-
isEnabled
public boolean isEnabled()
Description copied from interface:LockManagerReturns whether the lock manager is enabled.- Specified by:
isEnabledin interfaceLockManager- Returns:
- true if server
-
cleanupUserTokens
public void cleanupUserTokens(Db session, long userId)
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
public void initialize(Db session)
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
public <T extends PersistentDomainObject<T>> TokenLock getLock(T pdo)
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
public Collection<TokenLock> getLocks(long userId)
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
public Collection<TokenLock> getLocks()
Description copied from interface:LockManagerGets all token locks.- Specified by:
getLocksin interfaceLockManager- Returns:
- the token locks
-
update
public <T extends PersistentDomainObject<T>> void update(T pdo)
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
public void rollback(Db session, long txNumber)
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
public void commit(Db session, long txNumber)
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
-
remove
protected void remove(DbTokenLock lock, DomainContext context)
Removes a token lock from the lock table and the PDO.- Parameters:
lock- the token lockcontext- the application's domain context
-
createTokenLock
protected DbTokenLock createTokenLock(Db session)
Creates a tokenlock persistent object.- Parameters:
session- the session- Returns:
- the PO
-
reloadLocks
protected void reloadLocks(Db session)
Reloads locks from the database into the internal map.
There must be no transactions running!- Parameters:
session- the session
-
-