Interface LockManager

  • All Known Implementing Classes:
    DefaultLockManager

    public interface LockManager
    Manager for token locks.

    The lock manager maintains the state of all token locks in parallel to the editedBy-tokens of the PDOs.
    This allows to know all locks without the need to scan the PDO tables.

    The lock manager is used for 2 purposes:

    1. If a client session crashes, the locks held by the session's user are removed.
    2. When the server crashes, all locks are removed at server start.
    Notice that only servers provide an enabled lock manager. In 2-tier applications the lockmanager is disabled and in remote clients not used at all.
    See Also:
    DefaultLockManager
    • Method Detail

      • getInstance

        static LockManager getInstance()
        The singleton.
        Returns:
        the singleton
      • isEnabled

        boolean isEnabled()
        Returns whether the lock manager is enabled.
        Returns:
        true if server
      • cleanupUserTokens

        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.
        Parameters:
        session - the session to use
        userId - the user id
      • initialize

        void initialize​(Db session)
        Initializes the lockmanager.
        Called once at server startup to remove all locks.
        Parameters:
        session - the session to use
      • getLock

        <T extends PersistentDomainObject<T>> TokenLock getLock​(T pdo)
        Gets the token lock for a PDO.
        Type Parameters:
        T - the PDO type
        Parameters:
        pdo - the PDO
        Returns:
        the token lock, null if PDO is not locked
      • getLocks

        Collection<TokenLock> getLocks​(long userId)
        Gets the token locks for a user.
        Parameters:
        userId - the user's ID
        Returns:
        the token locks
      • update

        <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.
        Type Parameters:
        T - the PDO type
        Parameters:
        pdo - the PDO
      • commit

        void commit​(Db session,
                    long txNumber)
        Notifies the lockmanager that a transaction has been committed.
        Parameters:
        session - the session
        txNumber - the unique transaction number
      • rollback

        void rollback​(Db session,
                      long txNumber)
        Notifies the lockmanager that a transaction has been rolled back.
        Parameters:
        session - the session
        txNumber - the unique transaction number