com.github.sadstool.redissonaspectlock.lock.LockFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson-aspect-lock Show documentation
Show all versions of redisson-aspect-lock Show documentation
redisson aspect lock for spring
The newest version!
package com.github.sadstool.redissonaspectlock.lock;
import com.github.sadstool.redissonaspectlock.attributes.LockAttributes;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LockFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(LockFactory.class);
private RedissonClient redissonClient;
public LockFactory(RedissonClient redissonClient) {
this.redissonClient = redissonClient;
}
public Lock create(LockAttributes attributes) {
String path = attributes.getPath();
long waitTime = attributes.getWaitTime();
long leaseTime = attributes.getLeaseTime();
LOGGER.trace("Creating lock with name '{}', path '{}', waitTime {} and leaseTime {}", attributes.getName(),
path, waitTime, leaseTime);
RLock lock = redissonClient.getLock(path);
return new RedissonLock(lock, waitTime, leaseTime);
}
}