Package org.glassfish.api.admin
Class AdminCommandLock
- java.lang.Object
-
- org.glassfish.api.admin.AdminCommandLock
-
@Service @Singleton public class AdminCommandLock extends Object
The implementation of the admin command lock.- Author:
- Bill Shannon, Chris Kasso
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AdminCommandLock.SuspendStatus
The status of a suspend command attempt.
-
Constructor Summary
Constructors Constructor Description AdminCommandLock()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dumpState(Logger logger, Level level)
Lock
getLock(AdminCommand command)
Return the appropriate Lock object for the specified command.Lock
getLock(AdminCommand command, String owner)
Return the appropriate Lock object for the specified command.Lock
getLock(CommandLock.LockType type)
Return the appropriate Lock object for the specified LockType.String
getLockMessage()
Get the message to be returned if the lock could not be acquired.String
getLockOwner()
Get the admin user id for the user who acquired the exclusive lock.Date
getLockTimeOfAcquisition()
Get the time the exclusive lock was acquired.boolean
isSuspended()
Indicates if commands are currently suspended.Thread
resumeCommands()
Release the lock allowing the DAS to accept commands.static void
runWithSuspendedLock(Runnable r)
Use this method to temporarily suspend the command lock during which other operations may be performed.AdminCommandLock.SuspendStatus
suspendCommands(long timeout, String lockOwner)
Lock the DAS from accepting any commands annotated with a SHARED or EXCLUSIVE CommandLock.AdminCommandLock.SuspendStatus
suspendCommands(long timeout, String lockOwner, String message)
Lock the DAS from accepting any commands annotated with a SHARED or EXCLUSIVE CommandLock.
-
-
-
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
-
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
-
getLock
public Lock getLock(AdminCommand command, String owner) throws AdminCommandLockTimeoutException, AdminCommandLockException
Return the appropriate Lock object for the specified command. The returned lock has been locked. If this command needs no lock, null is returned.- Parameters:
command
- the AdminCommand objectowner
- the authority who requested the lock- Returns:
- the Lock object to use, or null if no lock needed
- Throws:
AdminCommandLockTimeoutException
AdminCommandLockException
-
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 secondslockOwner
- 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 secondslockOwner
- the user who acquired the lockmessage
- 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
-
-