Class DefaultLockManager

java.lang.Object
org.tentackle.persist.lock.DefaultLockManager
All Implemented Interfaces:
LockManager

@Service(LockManager.class) public class DefaultLockManager extends Object implements 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

    Constructors
    Constructor
    Description
    Creates the lock manager.
    Enabled only if running within a server application.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    cleanupUserTokens(Db session, long userId)
    Removes all tokens for a given user.
    The method is invoked when a user logs out or its session crashed.
    void
    commit(Db session, long txNumber)
    Notifies the lockmanager that a transaction has been committed.
    protected DbTokenLock
    Creates a tokenlock persistent object.
    getLock(T pdo)
    Gets the token lock for a PDO.
    Gets all token locks.
    getLocks(long userId)
    Gets the token locks for a user.
    void
    initialize(Db session)
    Initializes the lockmanager.
    Called once at server startup to remove all locks.
    boolean
    Returns whether the lock manager is enabled.
    protected boolean
    Returns whether a token lock should be kept on session cleanup or after server start.
    The default implementation returns false.
    protected void
    reloadLocks(Db session)
    Reloads locks from the database into the internal map.
    There must be no transactions running!
    void
    rollback(Db session, long txNumber)
    Notifies the lockmanager that a transaction has been rolled back.
    <T extends PersistentDomainObject<T>>
    void
    update(T pdo)
    Updates the lock token.
    The method is invoked from within a transaction after the PDO has been persisted successfully.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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: LockManager
      Returns whether the lock manager is enabled.
      Specified by:
      isEnabled in interface LockManager
      Returns:
      true if server
    • cleanupUserTokens

      public void cleanupUserTokens(Db session, long userId)
      Description copied from interface: LockManager
      Removes all tokens for a given user.
      The method is invoked when a user logs out or its session crashed.
      Specified by:
      cleanupUserTokens in interface LockManager
      Parameters:
      session - the session to use
      userId - the user id
    • initialize

      public void initialize(Db session)
      Description copied from interface: LockManager
      Initializes the lockmanager.
      Called once at server startup to remove all locks.
      Specified by:
      initialize in interface LockManager
      Parameters:
      session - the session to use
    • getLock

      public <T extends PersistentDomainObject<T>> TokenLock getLock(T pdo)
      Description copied from interface: LockManager
      Gets the token lock for a PDO.
      Specified by:
      getLock in interface LockManager
      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: LockManager
      Gets the token locks for a user.
      Specified by:
      getLocks in interface LockManager
      Parameters:
      userId - the user's ID
      Returns:
      the token locks
    • getLocks

      public Collection<TokenLock> getLocks()
      Description copied from interface: LockManager
      Gets all token locks.
      Specified by:
      getLocks in interface LockManager
      Returns:
      the token locks
    • update

      public <T extends PersistentDomainObject<T>> void update(T pdo)
      Description copied from interface: LockManager
      Updates the lock token.
      The method is invoked from within a transaction after the PDO has been persisted successfully.
      Specified by:
      update in interface LockManager
      Type Parameters:
      T - the PDO type
      Parameters:
      pdo - the PDO
    • rollback

      public void rollback(Db session, long txNumber)
      Description copied from interface: LockManager
      Notifies the lockmanager that a transaction has been rolled back.
      Specified by:
      rollback in interface LockManager
      Parameters:
      session - the session
      txNumber - the unique transaction number
    • commit

      public void commit(Db session, long txNumber)
      Description copied from interface: LockManager
      Notifies the lockmanager that a transaction has been committed.
      Specified by:
      commit in interface LockManager
      Parameters:
      session - the session
      txNumber - the unique transaction number
    • createTokenLock

      protected DbTokenLock createTokenLock(Db session)
      Creates a tokenlock persistent object.
      Parameters:
      session - the session
      Returns:
      the PO
    • isTokenLockToKeep

      protected boolean isTokenLockToKeep(DbTokenLock dbTokenLock, DomainContext context)
      Returns whether a token lock should be kept on session cleanup or after server start.
      The default implementation returns false.
      Parameters:
      dbTokenLock - the token lock
      context - the domain context to use
      Returns:
      true to keep it
    • reloadLocks

      protected void reloadLocks(Db session)
      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