Class LockRegistry<T extends ManagedClusterLock>
- Type Parameters:
T- the type ofManagedClusterLockthat this registry tracks
ManagedClusterLockService implementations.
The lock registry maintains a unique mapping of lock names to corresponding ClusterLock objects on
behalf of a ManagedClusterLockService. Lock services that use this registry to manage this mapping
should implement ManagedClusterLockService.getAllKnownClusterLocks(),
ManagedClusterLockService.getAllKnownClusterLocks(), and ClusterLockService.getLockForName(String) by
delegating them to the lock registry.
- Since:
- v0.2
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract TcreateLock(String lockName, String pluginKey) Creates a new cluster lock with the given name.A delegate implementation forManagedClusterLockService.getAllKnownClusterLocks()that will return all registeredManagedClusterLockinstances that have previously been returned by calls togetLockForName(String).getLockForName(String lockName) A delegate implementation forClusterLockService.getLockForName(String)that will ensure that the same lock instance is returned on every call.A delegate implementation forManagedClusterLockService.getStatusesOfAllHeldClusterLocks()that will returnClusterLockStatusfor every lock being held.
-
Constructor Details
-
LockRegistry
public LockRegistry()
-
-
Method Details
-
getAllKnownClusterLocks
A delegate implementation forManagedClusterLockService.getAllKnownClusterLocks()that will return all registeredManagedClusterLockinstances that have previously been returned by calls togetLockForName(String).- Returns:
- an immutable collection of all the known cluster locks, in no particular order
-
getStatusesOfAllHeldClusterLocks
A delegate implementation forManagedClusterLockService.getStatusesOfAllHeldClusterLocks()that will returnClusterLockStatusfor every lock being held.- Returns:
- an immutable collection of cluster lock statuses, in no particular order
-
getLockForName
A delegate implementation forClusterLockService.getLockForName(String)that will ensure that the same lock instance is returned on every call.- Parameters:
lockName- the name of the lock- Returns:
- a new lock if this
lockNamehas not previously been requested; otherwise, the same lock instance that was previously returned for it
-
createLock
Creates a new cluster lock with the given name.WARNING: This method may be called by multiple threads at once. The implementation of
getLockForName(String)will ensure that only one of the created lock instances is ever returned, but this factory method must create lock objects for which creating an extra lock of the same name causes no problems so long as the extra lock is never actually used. If this in not possible, then the cluster lock service should implementClusterLockService.getLockForName(String)andManagedClusterLockService.getAllKnownClusterLocks()directly instead of using this lock registry.- Parameters:
lockName- the name of the lock to createpluginKey- the name of the plugin that created this lock- Returns:
- the newly create lock, which may or may not actually end up being used
-