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 voidacquireLock(ScheduledJobParameter jobParameter, JobExecutionContext context, org.opensearch.action.ActionListener<LockModel> listener)Attempts to acquire lock the job.voiddeleteLock(java.lang.String lockId, org.opensearch.action.ActionListener<java.lang.Boolean> listener)Attempt to delete lock.booleanlockIndexExist()voidrelease(LockModel lock, org.opensearch.action.ActionListener<java.lang.Boolean> listener)Attempt to release the lock.voidrenewLock(LockModel lock, org.opensearch.action.ActionListener<LockModel> listener)Attempt to renew a lock.
-
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- aScheduledJobParametercontaining the lock duration.context- aJobExecutionContextcontaining job index name and job id.listener- anActionListenerthat has onResponse and onFailure that is used to return the lock if it was acquired or else null. PassesIllegalArgumentExceptionto onFailure if theScheduledJobParameterdoes not haveLockDurationSeconds.
-
release
public void release(LockModel lock, org.opensearch.action.ActionListener<java.lang.Boolean> listener)Attempt to release the lock. Most failure cases are due tolock.seqNoandlock.primaryTermnot matching with the existing document.- Parameters:
lock- aLockModelto be released.listener- aActionListenerthat 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- aStringto be deleted.listener- anActionListenerthat has onResponse and onFailure that is used to return whether or not the delete was successful
-
renewLock
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- aLockModelto be renewed.listener- aActionListenerthat has onResponse and onFailure that is used to return the renewed lock if renewal succeed, otherwise return null.
-