refactoring

pull/365/head
Nikita 9 years ago
parent c3dd888b96
commit 80a1ea194c

@ -49,8 +49,6 @@ public class RedissonLock extends RedissonExpirable implements RLock {
final UUID id;
public static final Long unlockMessage = 0L;
private static final LockPubSub PUBSUB = new LockPubSub();
final CommandExecutor commandExecutor;
@ -287,7 +285,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
"return 1; "+
"end; " +
"return nil;",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage, internalLockLeaseTime, getLockName());
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage, internalLockLeaseTime, getLockName());
if (opStatus == null) {
throw new IllegalMonitorStateException("attempt to unlock read lock, not locked by current thread by node id: "
+ id + " thread-id: " + Thread.currentThread().getId());
@ -317,7 +315,7 @@ public class RedissonLock extends RedissonExpirable implements RLock {
+ "else "
+ "return 0 "
+ "end",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage);
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage);
}
@Override

@ -25,6 +25,7 @@ import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.core.RLock;
import org.redisson.pubsub.LockPubSub;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
@ -96,7 +97,7 @@ public class RedissonReadLock extends RedissonLock implements RLock {
"end; " +
"end; " +
"return nil; ",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage, internalLockLeaseTime, getLockName());
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage, internalLockLeaseTime, getLockName());
if (opStatus == null) {
throw new IllegalMonitorStateException("attempt to unlock read lock, not locked by current thread by node id: "
+ id + " thread-id: " + Thread.currentThread().getId());
@ -120,7 +121,7 @@ public class RedissonReadLock extends RedissonLock implements RLock {
"else " +
"return 0; " +
"end;",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage);
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage);
result.addListener(new FutureListener<Boolean>() {
@Override

@ -41,8 +41,6 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
final UUID id;
public static final Long unlockMessage = 0L;
private static final LockPubSub PUBSUB = new LockPubSub();
final CommandExecutor commandExecutor;
@ -173,7 +171,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
commandExecutor.evalWrite(getName(), StringCodec.INSTANCE, RedisCommands.EVAL_OBJECT,
"redis.call('incrby', KEYS[1], ARGV[1]); " +
"redis.call('publish', KEYS[2], ARGV[2]); ",
Arrays.<Object>asList(getName(), getChannelName()), permits, unlockMessage);
Arrays.<Object>asList(getName(), getChannelName()), permits, LockPubSub.unlockMessage);
}
@Override
@ -206,7 +204,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
+ "redis.call('set', KEYS[1], ARGV[2]); "
+ "redis.call('publish', KEYS[2], ARGV[1]); "
+ "end;",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage, permits);
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage, permits);
get(f);
}

@ -25,6 +25,7 @@ import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandExecutor;
import org.redisson.core.RLock;
import org.redisson.pubsub.LockPubSub;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
@ -98,7 +99,7 @@ public class RedissonWriteLock extends RedissonLock implements RLock {
"end; " +
"end; "
+ "return nil;",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage, internalLockLeaseTime, getLockName());
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage, internalLockLeaseTime, getLockName());
if (opStatus == null) {
throw new IllegalMonitorStateException("attempt to unlock read lock, not locked by current thread by node id: "
+ id + " thread-id: " + Thread.currentThread().getId());
@ -122,7 +123,7 @@ public class RedissonWriteLock extends RedissonLock implements RLock {
"else " +
"return 0; " +
"end;",
Arrays.<Object>asList(getName(), getChannelName()), unlockMessage);
Arrays.<Object>asList(getName(), getChannelName()), LockPubSub.unlockMessage);
result.addListener(new FutureListener<Boolean>() {
@Override

@ -15,13 +15,14 @@
*/
package org.redisson.pubsub;
import org.redisson.RedissonLock;
import org.redisson.RedissonLockEntry;
import io.netty.util.concurrent.Promise;
public class LockPubSub extends PublishSubscribe<RedissonLockEntry> {
public static final Long unlockMessage = 0L;
@Override
protected RedissonLockEntry createEntry(Promise<RedissonLockEntry> newPromise) {
return new RedissonLockEntry(newPromise);
@ -29,7 +30,7 @@ public class LockPubSub extends PublishSubscribe<RedissonLockEntry> {
@Override
protected void onMessage(RedissonLockEntry value, Long message) {
if (message.equals(RedissonLock.unlockMessage)) {
if (message.equals(unlockMessage)) {
value.getLatch().release();
}
}

Loading…
Cancel
Save