Class LockService

java.lang.Object
org.opensearch.jobscheduler.spi.utils.LockService

public final class LockService
extends java.lang.Object
  • Constructor Summary

    Constructors 
    Constructor Description
    LockService​(org.opensearch.client.Client client, org.opensearch.cluster.service.ClusterService clusterService)  
  • Method Summary

    Modifier and Type Method Description
    void acquireLock​(ScheduledJobParameter jobParameter, JobExecutionContext context, org.opensearch.action.ActionListener<LockModel> listener)
    Attempts to acquire lock the job.
    void deleteLock​(java.lang.String lockId, org.opensearch.action.ActionListener<java.lang.Boolean> listener)
    Attempt to delete lock.
    boolean lockIndexExist()  
    void release​(LockModel lock, org.opensearch.action.ActionListener<java.lang.Boolean> listener)
    Attempt to release the lock.
    void renewLock​(LockModel lock, org.opensearch.action.ActionListener<LockModel> listener)
    Attempt to renew a lock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LockService

      public LockService​(org.opensearch.client.Client client, org.opensearch.cluster.service.ClusterService clusterService)
  • Method Details

    • lockIndexExist

      public boolean lockIndexExist()
    • acquireLock

      public void acquireLock​(ScheduledJobParameter jobParameter, JobExecutionContext context, org.opensearch.action.ActionListener<LockModel> listener)
      Attempts to acquire lock the job. If the lock does not exists it attempts to create the lock document. If the Lock document exists, it will try to update and acquire lock.
      Parameters:
      jobParameter - a ScheduledJobParameter containing the lock duration.
      context - a JobExecutionContext containing job index name and job id.
      listener - an ActionListener that has onResponse and onFailure that is used to return the lock if it was acquired or else null. Passes IllegalArgumentException to onFailure if the ScheduledJobParameter does not have LockDurationSeconds.
    • release

      public void release​(LockModel lock, org.opensearch.action.ActionListener<java.lang.Boolean> listener)
      Attempt to release the lock. Most failure cases are due to lock.seqNo and lock.primaryTerm not matching with the existing document.
      Parameters:
      lock - a LockModel to be released.
      listener - a ActionListener that has onResponse and onFailure that is used to return whether or not the release was successful
    • deleteLock

      public void deleteLock​(java.lang.String lockId, org.opensearch.action.ActionListener<java.lang.Boolean> listener)
      Attempt to delete lock. This should be called as part of clean up when the job for corresponding lock is deleted.
      Parameters:
      lockId - a String to be deleted.
      listener - an ActionListener that has onResponse and onFailure that is used to return whether or not the delete was successful
    • renewLock

      public void renewLock​(LockModel lock, org.opensearch.action.ActionListener<LockModel> listener)
      Attempt to renew a lock. It is used to give an extended valid period to a lock. The start time of the lock will be updated to the current time when the method get called, and the duration of the lock remains. It works as long as the lock is not acquired by others, and no matter if the lock is expired of not.
      Parameters:
      lock - a LockModel to be renewed.
      listener - a ActionListener that has onResponse and onFailure that is used to return the renewed lock if renewal succeed, otherwise return null.