INT-4248-4.3: Deprecate RedisLockRegistry methods

JIRA: https://jira.spring.io/browse/INT-4248

Some methods in `RedisLockRegistry` is planed for removal in `5.0` because of
new architecture.
Therefore mark them `@Deprecated` in `4.3.x`
This commit is contained in:
Artem Bilan
2017-04-19 12:36:47 -04:00
committed by Gary Russell
parent ecc6824a8c
commit 12d2d8c677
2 changed files with 12 additions and 22 deletions

View File

@@ -136,6 +136,7 @@ public final class RedisLockRegistry implements LockRegistry {
* @param registryKey The key prefix for locks.
* @param expireAfter The expiration in milliseconds.
*/
@SuppressWarnings("deprecation")
public RedisLockRegistry(RedisConnectionFactory connectionFactory, String registryKey, long expireAfter) {
this(connectionFactory, registryKey, expireAfter, new DefaultLockRegistry());
}
@@ -147,7 +148,9 @@ public final class RedisLockRegistry implements LockRegistry {
* @param expireAfter The expiration in milliseconds.
* @param localRegistry The local registry used to reduce wait time,
* {@link DefaultLockRegistry} is used by default.
* @deprecated since 4.3.10, will be removed in 5.0, - the {@code localRegistry} isn't used any more
*/
@Deprecated
public RedisLockRegistry(RedisConnectionFactory connectionFactory, String registryKey,
long expireAfter, LockRegistry localRegistry) {
Assert.notNull(connectionFactory, "'connectionFactory' cannot be null");
@@ -172,7 +175,9 @@ public final class RedisLockRegistry implements LockRegistry {
* different {@link RedisLock} objects for same unlocked key.
* @param useWeakReferences set to true for switch thread local weak references storage on, false by default
* @since 4.0.7
* @deprecated since 4.3.10, will be removed in 5.0, - the thread local cache isn't used any more
*/
@Deprecated
public void setUseWeakReferences(boolean useWeakReferences) {
this.useWeakReferences = useWeakReferences;
}
@@ -292,6 +297,12 @@ public final class RedisLockRegistry implements LockRegistry {
return lock;
}
/**
* A list of locks in store for this {@link #registryKey}.
* @return the list of locks in store for this {@link #registryKey}
* @deprecated since 4.3.10, will be removed in 5.0 to avoid deserialized locks created in different process
*/
@Deprecated
public Collection<Lock> listLocks() {
return this.redisTemplate.execute(new RedisCallback<Collection<Lock>>() {

View File

@@ -352,24 +352,6 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
assertNull(TestUtils.getPropertyValue(registry, "hardThreadLocks", ThreadLocal.class).get());
}
@Test
@RedisAvailable
public void testList() throws Exception {
RedisLockRegistry registry = new RedisLockRegistry(this.getConnectionFactoryForTest(), this.registryKey);
Lock foo = registry.obtain("foo");
foo.lockInterruptibly();
Lock bar = registry.obtain("bar");
bar.lockInterruptibly();
Lock baz = registry.obtain("baz");
baz.lockInterruptibly();
Collection<Lock> locks = registry.listLocks();
assertEquals(3, locks.size());
foo.unlock();
bar.unlock();
baz.unlock();
assertNull(TestUtils.getPropertyValue(registry, "hardThreadLocks", ThreadLocal.class).get());
}
@Test
@RedisAvailable
public void testExpireNoLockInStore() throws Exception {
@@ -391,7 +373,6 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
@RedisAvailable
public void testExpireDuringSecondObtain() throws Exception {
RedisLockRegistry registry = new RedisLockRegistry(this.getConnectionFactoryForTest(), this.registryKey, 100);
registry.setUseWeakReferences(true);
Lock foo = registry.obtain("foo");
foo.lockInterruptibly();
waitForExpire("foo");
@@ -433,13 +414,12 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
public void testEquals() throws Exception {
RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
RedisLockRegistry registry1 = new RedisLockRegistry(connectionFactory, this.registryKey);
registry1.setUseWeakReferences(true);
RedisLockRegistry registry2 = new RedisLockRegistry(connectionFactory, this.registryKey);
RedisLockRegistry registry3 = new RedisLockRegistry(connectionFactory, this.registryKey2);
Lock lock1 = registry1.obtain("foo");
lock1.lock();
Lock lock2 = registry1.obtain("foo");
assertEquals(lock1, lock2);
lock1.lock();
lock2.lock();
assertEquals(lock1, lock2);
lock1.unlock();
@@ -466,7 +446,6 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
@RedisAvailable
public void testThreadLocalListLeaks() {
RedisLockRegistry registry = new RedisLockRegistry(this.getConnectionFactoryForTest(), this.registryKey, 100);
registry.setUseWeakReferences(true);
for (int i = 0; i < 10; i++) {
registry.obtain("foo" + i);