Class LockRegistry<T extends ManagedClusterLock>

java.lang.Object
com.atlassian.beehive.core.LockRegistry<T>
Type Parameters:
T - the type of ManagedClusterLock that this registry tracks

public abstract class LockRegistry<T extends ManagedClusterLock> extends Object
Provides a lock registry for 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 Details

    • LockRegistry

      public LockRegistry()
  • Method Details

    • getAllKnownClusterLocks

      public Collection<T> getAllKnownClusterLocks()
      A delegate implementation for ManagedClusterLockService.getAllKnownClusterLocks() that will return all registered ManagedClusterLock instances that have previously been returned by calls to getLockForName(String).
      Returns:
      an immutable collection of all the known cluster locks, in no particular order
    • getStatusesOfAllHeldClusterLocks

      public Collection<ClusterLockStatus> getStatusesOfAllHeldClusterLocks()
      A delegate implementation for ManagedClusterLockService.getStatusesOfAllHeldClusterLocks() that will return ClusterLockStatus for every lock being held.
      Returns:
      an immutable collection of cluster lock statuses, in no particular order
    • getLockForName

      public ClusterLock getLockForName(@Nonnull String lockName)
      A delegate implementation for ClusterLockService.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 lockName has not previously been requested; otherwise, the same lock instance that was previously returned for it
    • createLock

      protected abstract T createLock(@Nonnull String lockName, @Nullable String pluginKey)
      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 implement ClusterLockService.getLockForName(String) and ManagedClusterLockService.getAllKnownClusterLocks() directly instead of using this lock registry.

      Parameters:
      lockName - the name of the lock to create
      pluginKey - the name of the plugin that created this lock
      Returns:
      the newly create lock, which may or may not actually end up being used