Class AdminCommandLock


  • @Service
    @Singleton
    public class AdminCommandLock
    extends Object
    The implementation of the admin command lock.
    Author:
    Bill Shannon, Chris Kasso
    • Constructor Detail

      • AdminCommandLock

        public AdminCommandLock()
    • Method Detail

      • getLock

        public Lock getLock​(CommandLock.LockType type)
        Return the appropriate Lock object for the specified LockType. The returned lock has not been locked. If the LockType is not SHARED or EXCLUSIVE null is returned.
        Parameters:
        type - the LockType
        Returns:
        the Lock object to use, or null
      • dumpState

        public void dumpState​(Logger logger,
                              Level level)
      • getLock

        public Lock getLock​(AdminCommand command)
        Return the appropriate Lock object for the specified command. The returned lock has not been locked. If this command needs no lock, null is returned.
        Parameters:
        command - the AdminCommand object
        Returns:
        the Lock object to use, or null if no lock needed
      • getLockOwner

        public String getLockOwner()
        Get the admin user id for the user who acquired the exclusive lock. This does not imply the lock is still held.
        Returns:
        the admin user who acquired the lock
      • getLockMessage

        public String getLockMessage()
        Get the message to be returned if the lock could not be acquired.
        Returns:
        the message indicating why the domain is locked.
      • getLockTimeOfAcquisition

        public Date getLockTimeOfAcquisition()
        Get the time the exclusive lock was acquired. This does not imply the lock is still held.
        Returns:
        the time the lock was acquired
      • isSuspended

        public boolean isSuspended()
        Indicates if commands are currently suspended.
      • suspendCommands

        public AdminCommandLock.SuspendStatus suspendCommands​(long timeout,
                                                              String lockOwner)
        Lock the DAS from accepting any commands annotated with a SHARED or EXCLUSIVE CommandLock. This method will result in the acquisition of an EXCLUSIVE lock. This method will not return until the lock is acquired, it times out or an error occurs.
        Parameters:
        timeout - lock timeout in seconds
        lockOwner - the user who acquired the lock
        Returns:
        status regarding acquisition of the lock
      • suspendCommands

        public AdminCommandLock.SuspendStatus suspendCommands​(long timeout,
                                                              String lockOwner,
                                                              String message)
        Lock the DAS from accepting any commands annotated with a SHARED or EXCLUSIVE CommandLock. This method will result in the acquisition of an EXCLUSIVE lock. This method will not return until the lock is acquired, it times out or an error occurs.
        Parameters:
        timeout - lock timeout in seconds
        lockOwner - the user who acquired the lock
        message - message to return when a command is blocked
        Returns:
        status regarding acquisition of the lock
      • resumeCommands

        public Thread resumeCommands()
        Release the lock allowing the DAS to accept commands. This method may return before the lock is released. When the thread exits the lock will have been released.
        Returns:
        the thread maintaining the lock, null if the DAS is not in a suspended state. The caller may join() the thread to determine when the lock is released.
      • runWithSuspendedLock

        public static void runWithSuspendedLock​(Runnable r)
        Use this method to temporarily suspend the command lock during which other operations may be performed. When the method returns the lock will be reestablished. This method must be invoked from the same thread which acquired the original lock.
        Parameters:
        r - A Runnable which will be invoked by the method after the lock is suspended