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  
    • 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 called
      void releaseLock​(Job job, java.lang.String lockIdentifier)
      This method id called to release lock acquired using acquireLock(Job).
    • 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 return Job.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 using acquireLock(Job).

        This method is always called

        Parameters:
        job - the running job
        lockIdentifier - 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 interface Middleware
        Parameters:
        job - job object
        callable - next middleware in chain
        Throws:
        java.lang.Exception - any exception