Feature - getCountDownLatch, getPermitExpirableSemaphore, getSemaphore, getFairLock methods added to RMultimap object #1963

pull/1979/head
Nikita Koksharov 6 years ago
parent 7e94157530
commit 78264ec79a

@ -27,10 +27,13 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RCountDownLatch;
import org.redisson.api.RFuture;
import org.redisson.api.RLock;
import org.redisson.api.RMultimap;
import org.redisson.api.RPermitExpirableSemaphore;
import org.redisson.api.RReadWriteLock;
import org.redisson.api.RSemaphore;
import org.redisson.client.RedisClient;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.LongCodec;
@ -40,7 +43,6 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.decoder.MapScanResult;
import org.redisson.codec.CompositeCodec;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.command.CommandExecutor;
import org.redisson.misc.Hash;
import org.redisson.misc.RedissonPromise;
@ -67,24 +69,39 @@ public abstract class RedissonMultimap<K, V> extends RedissonExpirable implement
}
@Override
public RLock getLock(K key) {
String lockName = getLockName(key);
return new RedissonLock((CommandExecutor) commandExecutor, lockName);
public RLock getFairLock(K key) {
String lockName = getLockByMapKey(key, "fairlock");
return new RedissonFairLock(commandExecutor, lockName);
}
@Override
public RReadWriteLock getReadWriteLock(K key) {
String lockName = getLockName(key);
return new RedissonReadWriteLock((CommandExecutor) commandExecutor, lockName);
public RPermitExpirableSemaphore getPermitExpirableSemaphore(K key) {
String lockName = getLockByMapKey(key, "permitexpirablesemaphore");
return new RedissonPermitExpirableSemaphore(commandExecutor, lockName);
}
private String getLockName(Object key) {
ByteBuf keyState = encodeMapKey(key);
try {
return suffixName(getName(), Hash.hash128toBase64(keyState) + ":key");
} finally {
keyState.release();
}
@Override
public RCountDownLatch getCountDownLatch(K key) {
String lockName = getLockByMapKey(key, "countdownlatch");
return new RedissonCountDownLatch(commandExecutor, lockName);
}
@Override
public RSemaphore getSemaphore(K key) {
String lockName = getLockByMapKey(key, "semaphore");
return new RedissonSemaphore(commandExecutor, lockName);
}
@Override
public RLock getLock(K key) {
String lockName = getLockByMapKey(key, "lock");
return new RedissonLock(commandExecutor, lockName);
}
@Override
public RReadWriteLock getReadWriteLock(K key) {
String lockName = getLockByMapKey(key, "rw_lock");
return new RedissonReadWriteLock(commandExecutor, lockName);
}
protected String hash(ByteBuf objectState) {

@ -29,6 +29,38 @@ import java.util.Set;
*/
public interface RMultimap<K, V> extends RExpirable, RMultimapAsync<K, V> {
/**
* Returns <code>RCountDownLatch</code> instance associated with key
*
* @param key - map key
* @return countdownlatch
*/
RCountDownLatch getCountDownLatch(K key);
/**
* Returns <code>RPermitExpirableSemaphore</code> instance associated with key
*
* @param key - map key
* @return permitExpirableSemaphore
*/
RPermitExpirableSemaphore getPermitExpirableSemaphore(K key);
/**
* Returns <code>RSemaphore</code> instance associated with key
*
* @param key - map key
* @return semaphore
*/
RSemaphore getSemaphore(K key);
/**
* Returns <code>RLock</code> instance associated with key
*
* @param key - map key
* @return fairlock
*/
RLock getFairLock(K key);
/**
* Returns <code>RReadWriteLock</code> instance associated with key
*

Loading…
Cancel
Save