Interface LockService

All Superinterfaces:
Distributable
All Known Implementing Classes:
DefaultLocalJvmLockService

public interface LockService extends Distributable
Basic LockService interface, specifically to be used by the Index processes to ensure that no other threads or nodes can start a specific full index process.

Author:
Kelly Tisdell (ktisdell)
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    isLocked(com.broadleafcommerce.search.api.type.IndexableType indexableType)
    Uses the provided IndexableType to find the lock.
    boolean
    isLocked(String lockName)
    Checks to see if a lock has already been acquired for the referenced object.
    default String
    lock(String lockName)
    Deprecated. 
    default Lock
    obtainLockInstance(com.broadleafcommerce.search.api.type.IndexableType indexableType)
    Provides a lock instance for the name provided by the provided IndexableType.
    This returns an instance of Lock, specifically for use with the specified lock name.
    default void
    unlock(String lockName, String lockKey)
    Deprecated. 

    Methods inherited from interface com.broadleafcommerce.search.index.core.Distributable

    isDistributed
  • Method Details

    • isLocked

      boolean isLocked(@NonNull String lockName)
      Checks to see if a lock has already been acquired for the referenced object.
      Parameters:
      lockName - the lock to check
      Returns:
      whether the lock has already been acquired
    • isLocked

      default boolean isLocked(@NonNull com.broadleafcommerce.search.api.type.IndexableType indexableType)
      Uses the provided IndexableType to find the lock. By default, this uses the IndexableType.getTopLevelAncestor() to determine the lock name.
      Parameters:
      indexableType - that can be used to resolve the Lock
      Returns:
      the Lock associated with the IndexableType
    • lock

      @Deprecated default String lock(@NonNull String lockName) throws LockException
      Deprecated.
      Attempts to create a lock based on the lock name. This does not necessarily synchronize or otherwise block threads. It just creates a lock reference for the for the specified lock name. Additional attempts to create a lock with the same name will fail until a call is made to the unlock method to unlock the lock for the specific lock name.
      Parameters:
      lockName - the lock to create
      Returns:
      the key for the created lock
      Throws:
      LockException - if a lock could not be obtained
      See Also:
    • unlock

      @Deprecated default void unlock(@NonNull String lockName, @NonNull String lockKey) throws LockException
      Deprecated.
      Attempts to unlock the lock for the given lock name.
      Parameters:
      lockName - the lock to unlock
      lockKey - the key for the lock
      Throws:
      LockException - if the lock could not be unlocked
      See Also:
    • obtainLockInstance

      Lock obtainLockInstance(@NonNull String lockName)
      This returns an instance of Lock, specifically for use with the specified lock name. This method should not lock or unlock, but should provide a shared Lock instance that can be used across threads. This method MUST return a lock with reentrant capabilities, meaning that a thread can lock the lock more than once before unlocking it. It is important, though, that a lock is unlocked as many times as it is locked. This method returns a particular instance of a Lock implementation, but users of the lock are responsible for locking and unlocking it.
      Parameters:
      lockName - the unique name for which to obtain a lock
      Returns:
      a shared Lock instance
      See Also:
    • obtainLockInstance

      default Lock obtainLockInstance(@NonNull com.broadleafcommerce.search.api.type.IndexableType indexableType)
      Provides a lock instance for the name provided by the provided IndexableType. In particular, if IndexableType.getTopLevelAncestor() is not null, then the parent's type will be used. Otherwise, the original argument's type will be used.
      Parameters:
      indexableType - the provided type
      Returns:
      a shared Lock instance