Class DefaultLocalJvmLockService

java.lang.Object
com.broadleafcommerce.search.index.core.DefaultLocalJvmLockService
All Implemented Interfaces:
Distributable, LockService

public class DefaultLocalJvmLockService extends Object implements LockService
This component allows for the tracking of a lock reference for a single process ID or reference.

By definition, this implementation is non-distributed and only works in a single JVM. Callers should obtain a lock and then call lock.tryLock() or equivalent. All, locks must be unlocked. The exact number of unlock calls must be made for successful lock and tryLock calls. By default, this returns a ReentrantLock, which is not distributed, and therefore not for use when there are multiple Indexer application nodes. However, ReentrantLock can be used for testing or when there is guaranteed to be only 1 Indexer node.

Author:
Kelly Tisdell (ktisdell)
  • Constructor Details

    • DefaultLocalJvmLockService

      public DefaultLocalJvmLockService()
  • Method Details

    • isDistributed

      public final boolean isDistributed()
      Description copied from interface: Distributable
      Indicates if this component is designed for use across JVMs.
      Specified by:
      isDistributed in interface Distributable
      Returns:
      whether this component can be distributed across JVMs
    • isLocked

      public boolean isLocked(@NonNull String lockName)
      Description copied from interface: LockService
      Checks to see if a lock has already been acquired for the referenced object.
      Specified by:
      isLocked in interface LockService
      Parameters:
      lockName - the lock to check
      Returns:
      whether the lock has already been acquired
    • obtainLockInstance

      public Lock obtainLockInstance(@NonNull String lockName)
      Description copied from interface: LockService
      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.
      Specified by:
      obtainLockInstance in interface LockService
      Parameters:
      lockName - the unique name for which to obtain a lock
      Returns:
      a shared Lock instance
      See Also:
    • obtainLockInterally

      protected ReentrantLock obtainLockInterally(@NonNull String lockName)