Interface LockMiddleware
-
- All Superinterfaces:
Middleware
,TimeProviderMiddleware
- All Known Implementing Classes:
RedisLockMiddleware
public interface LockMiddleware extends TimeProviderMiddleware
Lock middleware can be used for locking purpose Use cases:User's wallet amount should not be updated in parallel, in that case a lock on user's wallet account can be acquired to avoid parallel execution of task.
Only one task for a queue should be running at any point of time, in that case lock on the given queue can be acquired.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
REASON
-
Fields inherited from interface com.github.sonus21.rqueue.core.middleware.TimeProviderMiddleware
ONE_SECOND
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default 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.default void
handle(Job job, java.util.concurrent.Callable<java.lang.Void> callable)
Middleware handles that would be calledvoid
releaseLock(Job job, java.lang.String lockIdentifier)
This method id called to release lock acquired usingacquireLock(Job)
.-
Methods inherited from interface com.github.sonus21.rqueue.core.middleware.TimeProviderMiddleware
releaseIn
-
-
-
-
Field Detail
-
REASON
static final java.lang.String REASON
- See Also:
- Constant Field Values
-
-
Method Detail
-
acquireLock
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. 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()
.- Parameters:
job
- running job object- Returns:
- lock identifier
-
releaseLock
void releaseLock(Job job, java.lang.String lockIdentifier)
This method id called to release lock acquired usingacquireLock(Job)
.This method is always called
- Parameters:
job
- the running joblockIdentifier
- lock identifier
-
handle
default void handle(Job job, java.util.concurrent.Callable<java.lang.Void> callable) throws java.lang.Exception
Description copied from interface:Middleware
Middleware handles that would be called- Specified by:
handle
in interfaceMiddleware
- Parameters:
job
- job objectcallable
- next middleware in chain- Throws:
java.lang.Exception
- any exception
-
-