Class RedisLockMiddleware
- java.lang.Object
-
- com.github.sonus21.rqueue.core.middleware.RedisLockMiddleware
-
- All Implemented Interfaces:
LockMiddleware
,Middleware
,TimeProviderMiddleware
public abstract class RedisLockMiddleware extends java.lang.Object implements LockMiddleware
This uses Redis as backend for locking, using SETNX a lock is acquired.An implementation of this class must implement getLockIdentifier, that should return lock identifier for this job.
-
-
Field Summary
-
Fields inherited from interface com.github.sonus21.rqueue.core.middleware.LockMiddleware
REASON
-
Fields inherited from interface com.github.sonus21.rqueue.core.middleware.TimeProviderMiddleware
ONE_SECOND
-
-
Constructor Summary
Constructors Constructor Description RedisLockMiddleware(RqueueRedisTemplate<java.lang.String> template)
RedisLockMiddleware(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.String
acquireLock(Job job)
This method should acquire lock from any source like Redis, File, Java Lock or any system and returns lock identifier for the same.protected java.time.Duration
getLockDuration(Job job)
A lock can be required for forever or 1 second, that's all depends on the use case, bny default a lock is acquired for visibility time.protected abstract java.lang.String
getLockIdentifier(Job job)
Returns lock identifier for this job, could be a simple job id, user id or any other depending on the user case.void
releaseLock(Job job, java.lang.String lockIdentifier)
This method id called to release lock acquired usingLockMiddleware.acquireLock(Job)
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.sonus21.rqueue.core.middleware.LockMiddleware
handle
-
Methods inherited from interface com.github.sonus21.rqueue.core.middleware.TimeProviderMiddleware
releaseIn
-
-
-
-
Constructor Detail
-
RedisLockMiddleware
public RedisLockMiddleware(org.springframework.data.redis.connection.RedisConnectionFactory redisConnectionFactory)
-
RedisLockMiddleware
public RedisLockMiddleware(RqueueRedisTemplate<java.lang.String> template)
-
-
Method Detail
-
getLockIdentifier
protected abstract java.lang.String getLockIdentifier(Job job)
Returns lock identifier for this job, could be a simple job id, user id or any other depending on the user case. This method must returns non null value.- Parameters:
job
- job object- Returns:
- lock identifier
-
getLockDuration
protected java.time.Duration getLockDuration(Job job)
A lock can be required for forever or 1 second, that's all depends on the use case, bny default a lock is acquired for visibility time.- Parameters:
job
- job object- Returns:
- duration for this lock
-
releaseLock
public void releaseLock(Job job, java.lang.String lockIdentifier)
Description copied from interface:LockMiddleware
This method id called to release lock acquired usingLockMiddleware.acquireLock(Job)
.This method is always called
- Specified by:
releaseLock
in interfaceLockMiddleware
- Parameters:
job
- the running joblockIdentifier
- lock identifier
-
acquireLock
public java.lang.String acquireLock(Job job)
Description copied from interface:LockMiddleware
This method should acquire lock from any source like Redis, File, Java Lock or any system and returns lock identifier for the same. If it's unable to acquire lock than this method must return null/empty string.If locking system does not support lock identifier than you can returnJob.getId()
.- Specified by:
acquireLock
in interfaceLockMiddleware
- Parameters:
job
- running job object- Returns:
- lock identifier
-
-