Skip to content

Commit b30c57c

Browse files
committed
Rename CustomTtlLock to DistributedLock
Remove `CustomTtlLockRegistry`
1 parent ab861ba commit b30c57c

File tree

22 files changed

+61
-95
lines changed

22 files changed

+61
-95
lines changed

spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractCorrelatingMessageHandler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
130130

131131
private boolean sequenceAware;
132132

133-
private LockRegistry lockRegistry = new DefaultLockRegistry();
133+
private LockRegistry<?> lockRegistry = new DefaultLockRegistry();
134134

135135
private boolean lockRegistrySet = false;
136136

@@ -193,7 +193,7 @@ public AbstractCorrelatingMessageHandler(MessageGroupProcessor processor) {
193193
this(processor, new SimpleMessageStore(0), null, null);
194194
}
195195

196-
public void setLockRegistry(LockRegistry lockRegistry) {
196+
public void setLockRegistry(LockRegistry<?> lockRegistry) {
197197
Assert.isTrue(!this.lockRegistrySet, "'this.lockRegistry' can not be reset once its been set");
198198
Assert.notNull(lockRegistry, "'lockRegistry' must not be null");
199199
this.lockRegistry = lockRegistry;
@@ -499,7 +499,7 @@ protected boolean isSequenceAware() {
499499
return this.sequenceAware;
500500
}
501501

502-
protected LockRegistry getLockRegistry() {
502+
protected LockRegistry<?> getLockRegistry() {
503503
return this.lockRegistry;
504504
}
505505

spring-integration-core/src/main/java/org/springframework/integration/config/AggregatorFactoryBean.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class AggregatorFactoryBean extends AbstractSimpleMessageHandlerFactoryBe
6565

6666
private String outputChannelName;
6767

68-
private LockRegistry lockRegistry;
68+
private LockRegistry<?> lockRegistry;
6969

7070
private MessageGroupStore messageStore;
7171

@@ -122,7 +122,7 @@ public void setOutputChannelName(String outputChannelName) {
122122
this.outputChannelName = outputChannelName;
123123
}
124124

125-
public void setLockRegistry(LockRegistry lockRegistry) {
125+
public void setLockRegistry(LockRegistry<?> lockRegistry) {
126126
this.lockRegistry = lockRegistry;
127127
}
128128

spring-integration-core/src/main/java/org/springframework/integration/dsl/CorrelationHandlerSpec.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2022 the original author or authors.
2+
* Copyright 2016-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -299,7 +299,7 @@ public S forceReleaseAdvice(Advice... advice) {
299299
* @param lockRegistry the {@link LockRegistry} to use.
300300
* @return the endpoint spec.
301301
*/
302-
public S lockRegistry(LockRegistry lockRegistry) {
302+
public S lockRegistry(LockRegistry<?> lockRegistry) {
303303
Assert.notNull(lockRegistry, "'lockRegistry' must not be null.");
304304
this.handler.setLockRegistry(lockRegistry);
305305
return _this();

spring-integration-core/src/main/java/org/springframework/integration/metadata/PropertiesPersistingMetadataStore.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ public class PropertiesPersistingMetadataStore implements ConcurrentMetadataStor
6565

6666
private final DefaultPropertiesPersister persister = new DefaultPropertiesPersister();
6767

68-
private final LockRegistry lockRegistry = new DefaultLockRegistry();
68+
private final LockRegistry<Lock> lockRegistry = new DefaultLockRegistry();
6969

7070
private String baseDirectory = System.getProperty("java.io.tmpdir") + "/spring-integration/";
7171

spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageStore.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class SimpleMessageStore extends AbstractMessageGroupStore
7171

7272
private final long upperBoundTimeout;
7373

74-
private LockRegistry lockRegistry;
74+
private LockRegistry<?> lockRegistry;
7575

7676
private boolean copyOnGet = false;
7777

@@ -111,7 +111,7 @@ public SimpleMessageStore(int individualCapacity, int groupCapacity, long upperB
111111
* @param lockRegistry The lock registry.
112112
* @see #SimpleMessageStore(int, int, long, LockRegistry)
113113
*/
114-
public SimpleMessageStore(int individualCapacity, int groupCapacity, LockRegistry lockRegistry) {
114+
public SimpleMessageStore(int individualCapacity, int groupCapacity, LockRegistry<?> lockRegistry) {
115115
this(individualCapacity, groupCapacity, 0, lockRegistry);
116116
}
117117

@@ -126,7 +126,7 @@ public SimpleMessageStore(int individualCapacity, int groupCapacity, LockRegistr
126126
* @since 4.3
127127
*/
128128
public SimpleMessageStore(int individualCapacity, int groupCapacity, long upperBoundTimeout,
129-
LockRegistry lockRegistry) {
129+
LockRegistry<?> lockRegistry) {
130130

131131
super(false);
132132
Assert.notNull(lockRegistry, "The LockRegistry cannot be null");
@@ -162,7 +162,7 @@ public void setCopyOnGet(boolean copyOnGet) {
162162
this.copyOnGet = copyOnGet;
163163
}
164164

165-
public void setLockRegistry(LockRegistry lockRegistry) {
165+
public void setLockRegistry(LockRegistry<?> lockRegistry) {
166166
Assert.notNull(lockRegistry, "The LockRegistry cannot be null");
167167
Assert.isTrue(!(this.isUsed), "Cannot change the lock registry after the store has been used");
168168
this.lockRegistry = lockRegistry;

spring-integration-core/src/main/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class LockRegistryLeaderInitiator implements SmartLifecycle, DisposableBe
7474
* A lock registry. The locks it manages should be global (whatever that means for the
7575
* system) and expiring, in case the holder dies without notifying anyone.
7676
*/
77-
private final LockRegistry locks;
77+
private final LockRegistry<?> locks;
7878

7979
/**
8080
* Candidate for leader election. User injects this to receive callbacks on leadership
@@ -162,7 +162,7 @@ public String getRole() {
162162
* candidate (which just logs the leadership events).
163163
* @param locks lock registry
164164
*/
165-
public LockRegistryLeaderInitiator(LockRegistry locks) {
165+
public LockRegistryLeaderInitiator(LockRegistry<?> locks) {
166166
this(locks, new DefaultCandidate());
167167
}
168168

@@ -172,7 +172,7 @@ public LockRegistryLeaderInitiator(LockRegistry locks) {
172172
* @param locks lock registry
173173
* @param candidate leadership election candidate
174174
*/
175-
public LockRegistryLeaderInitiator(LockRegistry locks, Candidate candidate) {
175+
public LockRegistryLeaderInitiator(LockRegistry<?> locks, Candidate candidate) {
176176
Assert.notNull(locks, "'locks' must not be null");
177177
Assert.notNull(candidate, "'candidate' must not be null");
178178
this.locks = locks;

spring-integration-core/src/main/java/org/springframework/integration/support/locks/CustomTtlLockRegistry.java

-29
This file was deleted.

spring-integration-core/src/main/java/org/springframework/integration/support/locks/DefaultLockRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @since 2.1.1
3535
*
3636
*/
37-
public final class DefaultLockRegistry implements LockRegistry {
37+
public final class DefaultLockRegistry implements LockRegistry<Lock> {
3838

3939
private final Lock[] lockTable;
4040

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import java.util.concurrent.locks.Lock;
2121

2222
/**
23-
* A {@link Lock} implementing this interface supports the spring distributed locks with custom time-to-live value per lock
23+
* A {@link Lock} implementing for spring distributed locks
2424
*
2525
* @author Eddie Cho
2626
*
2727
* @since 6.3
2828
*/
29-
public interface CustomTtlLock extends Lock {
29+
public interface DistributedLock extends Lock {
3030

3131
/**
3232
* Attempt to acquire a lock with a specific time-to-live

spring-integration-core/src/main/java/org/springframework/integration/support/locks/ExpirableLockRegistry.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,15 +16,18 @@
1616

1717
package org.springframework.integration.support.locks;
1818

19+
import java.util.concurrent.locks.Lock;
20+
1921
/**
2022
* A {@link LockRegistry} implementing this interface supports the removal of aged locks
2123
* that are not currently locked.
24+
* @param <L> The expected class of the lock implementation
2225
*
2326
* @author Gary Russell
2427
* @since 4.2
2528
*
2629
*/
27-
public interface ExpirableLockRegistry extends LockRegistry {
30+
public interface ExpirableLockRegistry<L extends Lock> extends LockRegistry<L> {
2831

2932
/**
3033
* Remove locks last acquired more than 'age' ago that are not currently locked.

spring-integration-core/src/main/java/org/springframework/integration/support/locks/LockRegistry.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626

2727
/**
2828
* Strategy for maintaining a registry of shared locks.
29+
* @param <L> The expected class of the lock implementation
2930
*
3031
* @author Oleg Zhurakousky
3132
* @author Gary Russell
@@ -34,14 +35,14 @@
3435
* @since 2.1.1
3536
*/
3637
@FunctionalInterface
37-
public interface LockRegistry {
38+
public interface LockRegistry<L extends Lock> {
3839

3940
/**
4041
* Obtain the lock associated with the parameter object.
4142
* @param lockKey The object with which the lock is associated.
4243
* @return The associated lock.
4344
*/
44-
Lock obtain(Object lockKey);
45+
L obtain(Object lockKey);
4546

4647
/**
4748
* Perform the provided task when the lock for the key is locked.

spring-integration-core/src/main/java/org/springframework/integration/support/locks/PassThruLockRegistry.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
3333
* @since 2.2
3434
*
3535
*/
36-
public final class PassThruLockRegistry implements LockRegistry {
36+
public final class PassThruLockRegistry implements LockRegistry<Lock> {
3737

3838
@Override
3939
public Lock obtain(Object lockKey) {

spring-integration-core/src/main/java/org/springframework/integration/support/locks/RenewableLockRegistry.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,16 +16,19 @@
1616

1717
package org.springframework.integration.support.locks;
1818

19+
import java.util.concurrent.locks.Lock;
20+
1921
/**
2022
* A {@link LockRegistry} implementing this interface supports the renewal
2123
* of the time to live of a lock.
24+
* @param <L> The expected class of the lock implementation
2225
*
2326
* @author Alexandre Strubel
2427
* @author Artem Bilan
2528
*
2629
* @since 5.4
2730
*/
28-
public interface RenewableLockRegistry extends LockRegistry {
31+
public interface RenewableLockRegistry<L extends Lock> extends LockRegistry<L> {
2932

3033
/**
3134
* Renew the time to live of the lock is associated with the parameter object.

spring-integration-core/src/test/java/org/springframework/integration/support/leader/LockRegistryLeaderInitiatorTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class LockRegistryLeaderInitiatorTests {
6161

6262
private CountDownLatch revoked = new CountDownLatch(1);
6363

64-
private final LockRegistry registry = new DefaultLockRegistry();
64+
private final LockRegistry<Lock> registry = new DefaultLockRegistry();
6565

6666
private final LockRegistryLeaderInitiator initiator =
6767
new LockRegistryLeaderInitiator(this.registry, new DefaultCandidate());
@@ -275,7 +275,7 @@ public void testExceptionFromLock() throws Exception {
275275
}
276276
}).given(mockLock).tryLock(anyLong(), any(TimeUnit.class));
277277

278-
LockRegistry registry = lockKey -> mockLock;
278+
LockRegistry<Lock> registry = lockKey -> mockLock;
279279

280280
CountDownLatch onGranted = new CountDownLatch(1);
281281

spring-integration-core/src/test/java/org/springframework/integration/support/locks/DefaultLockRegistryTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public void testBadMaskOutOfRange() { // 32bits
5656

5757
@Test
5858
public void testSingleLockCreation() {
59-
LockRegistry registry = new DefaultLockRegistry(0);
59+
LockRegistry<Lock> registry = new DefaultLockRegistry(0);
6060
Lock a = registry.obtain(23);
6161
Lock b = registry.obtain(new Object());
6262
Lock c = registry.obtain("hello");
@@ -67,7 +67,7 @@ public void testSingleLockCreation() {
6767

6868
@Test
6969
public void testSame() {
70-
LockRegistry registry = new DefaultLockRegistry();
70+
LockRegistry<Lock> registry = new DefaultLockRegistry();
7171
Lock lock1 = registry.obtain(new Object() {
7272

7373
@Override
@@ -87,7 +87,7 @@ public int hashCode() {
8787

8888
@Test
8989
public void testDifferent() {
90-
LockRegistry registry = new DefaultLockRegistry();
90+
LockRegistry<Lock> registry = new DefaultLockRegistry();
9191
Lock lock1 = registry.obtain(new Object() {
9292

9393
@Override
@@ -107,7 +107,7 @@ public int hashCode() {
107107

108108
@Test
109109
public void testAllDifferentAndSame() {
110-
LockRegistry registry = new DefaultLockRegistry(3);
110+
LockRegistry<Lock> registry = new DefaultLockRegistry(3);
111111
Lock[] locks = new Lock[4];
112112
locks[0] = registry.obtain(new Object() {
113113

@@ -213,7 +213,7 @@ public int hashCode() {
213213

214214
@Test
215215
public void cyclicBarrierIsBrokenWhenExecutedConcurrentlyInLock() throws Exception {
216-
LockRegistry registry = new DefaultLockRegistry(1);
216+
LockRegistry<Lock> registry = new DefaultLockRegistry(1);
217217

218218
CyclicBarrier cyclicBarrier = new CyclicBarrier(2);
219219
CountDownLatch brokenBarrierLatch = new CountDownLatch(2);
@@ -245,7 +245,7 @@ public void cyclicBarrierIsBrokenWhenExecutedConcurrentlyInLock() throws Excepti
245245

246246
@Test
247247
public void executeLockedIsTimedOutInOtherThread() throws Exception {
248-
LockRegistry registry = new DefaultLockRegistry(1);
248+
LockRegistry<Lock> registry = new DefaultLockRegistry(1);
249249

250250
String lockKey = "lockKey";
251251
Duration waitLockDuration = Duration.ofMillis(100);

spring-integration-file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
161161

162162
private boolean appendNewLine = false;
163163

164-
private LockRegistry lockRegistry = new PassThruLockRegistry();
164+
private LockRegistry<Lock> lockRegistry = new PassThruLockRegistry();
165165

166166
private int bufferSize = DEFAULT_BUFFER_SIZE;
167167

spring-integration-hazelcast/src/main/java/org/springframework/integration/hazelcast/lock/HazelcastLockRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Artem Bilan
3030
*/
31-
public class HazelcastLockRegistry implements LockRegistry {
31+
public class HazelcastLockRegistry implements LockRegistry<Lock> {
3232

3333
private final HazelcastInstance client;
3434

0 commit comments

Comments
 (0)