Fixed according to comments

Signed-off-by: Vorotyntsev <vorotyntsevdanila@gmail.com>
pull/3364/head
Vorotyntsev 4 years ago
parent 2c24a344a3
commit 9de51f42bd

@ -352,8 +352,8 @@ public class Redisson implements RedissonClient {
}
@Override
public RLock getSpinLock(String name, LockOptions.BackOffOptions backOffOptions) {
return new RedissonSpinLock(connectionManager.getCommandExecutor(), name, backOffOptions);
public RLock getSpinLock(String name, LockOptions.BackOff backOff) {
return new RedissonSpinLock(connectionManager.getCommandExecutor(), name, backOff);
}
@Override

@ -133,8 +133,8 @@ public class RedissonReactive implements RedissonReactiveClient {
}
@Override
public RLockReactive getSpinLock(String name, LockOptions.BackOffOptions backOffOptions) {
RedissonSpinLock spinLock = new RedissonSpinLock(commandExecutor, name, backOffOptions);
public RLockReactive getSpinLock(String name, LockOptions.BackOff backOff) {
RedissonSpinLock spinLock = new RedissonSpinLock(commandExecutor, name, backOff);
return ReactiveProxyBuilder.create(commandExecutor, spinLock, RLockReactive.class);
}

@ -121,8 +121,8 @@ public class RedissonRx implements RedissonRxClient {
}
@Override
public RLockRx getSpinLock(String name, LockOptions.BackOffOptions backOffOptions) {
RedissonSpinLock spinLock = new RedissonSpinLock(commandExecutor, name, backOffOptions);
public RLockRx getSpinLock(String name, LockOptions.BackOff backOff) {
RedissonSpinLock spinLock = new RedissonSpinLock(commandExecutor, name, backOff);
return RxProxyBuilder.create(commandExecutor, spinLock, RLockRx.class);
}

@ -44,16 +44,16 @@ public class RedissonSpinLock extends RedissonBaseLock {
protected long internalLockLeaseTime;
protected final LockOptions.BackOffOptions backOffOptions;
protected final LockOptions.BackOff backOff;
final CommandAsyncExecutor commandExecutor;
public RedissonSpinLock(CommandAsyncExecutor commandExecutor, String name,
LockOptions.BackOffOptions backOffOptions) {
LockOptions.BackOff backOff) {
super(commandExecutor, name);
this.commandExecutor = commandExecutor;
this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
this.backOffOptions = backOffOptions;
this.backOff = backOff;
}
@Override
@ -87,7 +87,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
if (ttl == null) {
return;
}
LockOptions.BackOffPolicy backOffPolicy = backOffOptions.create();
LockOptions.BackOffPolicy backOffPolicy = backOff.create();
while (ttl != null) {
long nextSleepPeriod = backOffPolicy.getNextSleepPeriod();
Thread.sleep(nextSleepPeriod);
@ -158,7 +158,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
return false;
}
LockOptions.BackOffPolicy backOffPolicy = backOffOptions.create();
LockOptions.BackOffPolicy backOffPolicy = backOff.create();
while (ttl != null) {
current = System.currentTimeMillis();
Thread.sleep(backOffPolicy.getNextSleepPeriod());
@ -244,7 +244,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
@Override
public RFuture<Void> lockAsync(long leaseTime, TimeUnit unit, long currentThreadId) {
RPromise<Void> result = new RedissonPromise<>();
LockOptions.BackOffPolicy backOffPolicy = backOffOptions.create();
LockOptions.BackOffPolicy backOffPolicy = backOff.create();
lockAsync(leaseTime, unit, currentThreadId, result, backOffPolicy);
return result;
@ -313,7 +313,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
RPromise<Boolean> result = new RedissonPromise<>();
AtomicLong time = new AtomicLong(unit.toMillis(waitTime));
LockOptions.BackOffPolicy backOffPolicy = backOffOptions.create();
LockOptions.BackOffPolicy backOffPolicy = backOff.create();
tryLock(leaseTime, unit, currentThreadId, result, time, backOffPolicy);
return result;

@ -27,7 +27,7 @@ public class LockOptions {
/**
* Factory for {@linkplain BackOffPolicy} class.
*/
public interface BackOffOptions {
public interface BackOff {
BackOffPolicy create();
}
@ -48,7 +48,7 @@ public class LockOptions {
* Back off algorithm, where sleep period starts with {@linkplain #initialDelay}, each time increases
* {@linkplain #multiplier} times but doesn't exceed {@linkplain #maxDelay}
*/
public static class ExponentialBackOffOptions implements BackOffOptions {
public static class ExponentialBackOff implements BackOff {
private long maxDelay = 128;
private long initialDelay = 1;
private int multiplier = 2;
@ -66,7 +66,7 @@ public class LockOptions {
* @param maxDelay - max sleep period. Has to be positive
* @return ExponentialBackOffOptions instance
*/
public ExponentialBackOffOptions maxDelay(long maxDelay) {
public ExponentialBackOff maxDelay(long maxDelay) {
if (maxDelay <= 0) {
throw new IllegalArgumentException("maxDelay should be positive");
}
@ -86,7 +86,7 @@ public class LockOptions {
* @param initialDelay - initial sleep period. Has to be positive
* @return ExponentialBackOffOptions instance
*/
public ExponentialBackOffOptions initialDelay(long initialDelay) {
public ExponentialBackOff initialDelay(long initialDelay) {
if (initialDelay <= 0) {
throw new IllegalArgumentException("initialDelay should be positive");
}
@ -106,7 +106,7 @@ public class LockOptions {
* @param multiplier - sleep period multiplier. Has to be positive
* @return ExponentialBackOffOptions instance
*/
public ExponentialBackOffOptions multiplier(int multiplier) {
public ExponentialBackOff multiplier(int multiplier) {
if (multiplier <= 0) {
throw new IllegalArgumentException("multiplier should be positive");
}
@ -152,7 +152,7 @@ public class LockOptions {
* To reduce possible negative effects of many threads simultaneously sending requests, a small random value is
* added to all sleep periods.
*/
public static class ConstantBackOffOptions implements BackOffOptions {
public static class ConstantBackOff implements BackOff {
private long delay = 64;
@Override
@ -168,7 +168,7 @@ public class LockOptions {
* @param delay - sleep period value. Has to be positive
* @return ConstantBackOffOptions instance
*/
public ConstantBackOffOptions delay(long delay) {
public ConstantBackOff delay(long delay) {
if (delay <= 0) {
throw new IllegalArgumentException("delay should be positive");
}
@ -203,7 +203,7 @@ public class LockOptions {
*
* @return BackOffOptions instance
*/
public static BackOffOptions defaults() {
return new ExponentialBackOffOptions();
public static BackOff defaults() {
return new ExponentialBackOff();
}
}

@ -497,7 +497,7 @@ public interface RedissonClient {
* @param name - name of object
* @return Lock object
*/
RLock getSpinLock(String name, LockOptions.BackOffOptions backOffOptions);
RLock getSpinLock(String name, LockOptions.BackOff backOff);
/**
* Returns MultiLock instance associated with specified <code>locks</code>

@ -187,7 +187,7 @@ public interface RedissonReactiveClient {
* @param name - name of object
* @return Lock object
*/
RLockReactive getSpinLock(String name, LockOptions.BackOffOptions backOffOptions);
RLockReactive getSpinLock(String name, LockOptions.BackOff backOff);
/**
* Returns MultiLock instance associated with specified <code>locks</code>

@ -186,7 +186,7 @@ public interface RedissonRxClient {
* @param name - name of object
* @return Lock object
*/
RLockRx getSpinLock(String name, LockOptions.BackOffOptions backOffOptions);
RLockRx getSpinLock(String name, LockOptions.BackOff backOff);
/**
* Returns MultiLock instance associated with specified <code>locks</code>

@ -9,12 +9,12 @@ public class LockOptionsTest {
@Test
public void testExponentialBackoff() {
LockOptions.BackOffOptions backOffOptions = new LockOptions.ExponentialBackOffOptions()
LockOptions.BackOff backOff = new LockOptions.ExponentialBackOff()
.initialDelay(10)
.maxDelay(100)
.multiplier(3);
LockOptions.BackOffPolicy backOffPolicy = backOffOptions.create();
LockOptions.BackOffPolicy backOffPolicy = backOff.create();
assertThat(backOffPolicy.getNextSleepPeriod()).isBetween(10L, 10L);
@ -26,7 +26,7 @@ public class LockOptionsTest {
@Test
public void testConstantBackoff() {
LockOptions.ConstantBackOffOptions backOffOptions = new LockOptions.ConstantBackOffOptions()
LockOptions.ConstantBackOff backOffOptions = new LockOptions.ConstantBackOff()
.delay(30);
LockOptions.BackOffPolicy backOffPolicy = backOffOptions.create();

Loading…
Cancel
Save