Skip to content

Commit bdd435a

Browse files
committed
addres first batch of review suggestions
1 parent b9fe7ff commit bdd435a

File tree

22 files changed

+60
-122
lines changed

22 files changed

+60
-122
lines changed

spring-integration-core/src/test/java/org/springframework/integration/core/TimeBasedUUIDGenerator.java

Lines changed: 4 additions & 10 deletions
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-2022 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.
@@ -19,20 +19,17 @@
1919
import java.net.InetAddress;
2020
import java.net.NetworkInterface;
2121
import java.util.UUID;
22-
import java.util.concurrent.locks.Lock;
23-
import java.util.concurrent.locks.ReentrantLock;
2422
import java.util.logging.Logger;
2523

2624

2725
/**
2826
* @author Oleg Zhurakousky
2927
* @author Artem Bilan
30-
* @author Christian Tzolov
3128
*
3229
*/
3330
class TimeBasedUUIDGenerator {
3431

35-
static final Lock lock = new ReentrantLock();
32+
static final Object lock = new Object();
3633

3734
private static final Logger logger = Logger.getLogger(TimeBasedUUIDGenerator.class.getName());
3835

@@ -59,8 +56,7 @@ static UUID generateId() {
5956
static UUID generateIdFromTimestamp(long currentTimeMillis) {
6057
long time;
6158

62-
lock.lock();
63-
try {
59+
synchronized (lock) {
6460
if (currentTimeMillis > lastTime) {
6561
lastTime = currentTimeMillis;
6662
clockSequence = 0;
@@ -69,9 +65,7 @@ static UUID generateIdFromTimestamp(long currentTimeMillis) {
6965
++clockSequence;
7066
}
7167
}
72-
finally {
73-
lock.unlock();
74-
}
68+
7569

7670
time = currentTimeMillis;
7771

spring-integration-file/src/main/java/org/springframework/integration/file/locking/FileChannelCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static FileLock tryLockFor(File fileToLock) throws IOException {
7676
FileLock lock = null;
7777
if (channel != null) {
7878
try {
79-
lock = channel.lock();
79+
lock = channel.tryLock();
8080
}
8181
catch (OverlappingFileLockException e) {
8282
// File is already locked in this thread or virtual machine

spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/MulticastReceivingChannelAdapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class MulticastReceivingChannelAdapter extends UnicastReceivingChannelAda
4242

4343
private final String group;
4444

45-
private final Lock lock = new ReentrantLock();
46-
4745
/**
4846
* Constructs a MulticastReceivingChannelAdapter that listens for packets on the
4947
* specified multichannel address (group) and port.

spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public class MulticastSendingMessageHandler extends UnicastSendingMessageHandler
5151

5252
private volatile MulticastSocket multicastSocket;
5353

54-
private final Lock lock = new ReentrantLock();
55-
5654
/**
5755
* Constructs a MulticastSendingMessageHandler to send data to the multicast address/port.
5856
* @param address The multicast address.

spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastReceivingChannelAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class UnicastReceivingChannelAdapter extends AbstractInternetProtocolRece
5656

5757
private final DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
5858

59-
private final Lock lock = new ReentrantLock();
59+
protected final Lock lock = new ReentrantLock();
6060

6161
private DatagramSocket socket;
6262

spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/UnicastSendingMessageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class UnicastSendingMessageHandler extends
6969

7070
private static final int DEFAULT_ACK_TIMEOUT = 5000;
7171

72-
private final Lock lock = new ReentrantLock();
72+
protected final Lock lock = new ReentrantLock();
7373

7474
private final DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
7575

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/HelloWorldInterceptor.java

Lines changed: 2 additions & 12 deletions
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-2021 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.
@@ -18,8 +18,6 @@
1818

1919
import java.util.concurrent.Semaphore;
2020
import java.util.concurrent.TimeUnit;
21-
import java.util.concurrent.locks.Lock;
22-
import java.util.concurrent.locks.ReentrantLock;
2321

2422
import org.springframework.context.ApplicationEventPublisher;
2523
import org.springframework.integration.support.MessageBuilder;
@@ -28,15 +26,11 @@
2826

2927
/**
3028
* @author Gary Russell
31-
* @author Christian Tzolov
32-
*
3329
* @since 2.0
3430
*
3531
*/
3632
public class HelloWorldInterceptor extends TcpConnectionInterceptorSupport {
3733

38-
private final Lock lock = new ReentrantLock();
39-
4034
private volatile boolean negotiated;
4135

4236
private final Semaphore negotiationSemaphore = new Semaphore(0);
@@ -63,8 +57,7 @@ public HelloWorldInterceptor(String hello, String world, ApplicationEventPublish
6357
@Override
6458
public boolean onMessage(Message<?> message) {
6559
if (!this.negotiated) {
66-
this.lock.lock();
67-
try {
60+
synchronized (this) {
6861
if (!this.negotiated) {
6962
Object payload = message.getPayload();
7063
logger.debug(this.toString() + " received " + payload);
@@ -98,9 +91,6 @@ public boolean onMessage(Message<?> message) {
9891
}
9992
}
10093
}
101-
finally {
102-
this.lock.unlock();
103-
}
10494
}
10595
try {
10696
return super.onMessage(message);
Lines changed: 3 additions & 13 deletions
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-2019 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,31 +16,21 @@
1616

1717
package org.springframework.integration.jdbc;
1818

19-
import java.util.concurrent.locks.Lock;
2019
import java.util.concurrent.locks.ReentrantLock;
2120

2221
import org.aopalliance.intercept.MethodInterceptor;
2322
import org.aopalliance.intercept.MethodInvocation;
2423

2524
/**
2625
* @author Dave Syer
27-
* @author Christian Tzolov
2826
*
2927
*/
3028
public class LockInterceptor extends ReentrantLock implements MethodInterceptor {
3129

3230
private static final long serialVersionUID = 1L;
3331

34-
private final Lock lock = new ReentrantLock();
35-
36-
public Object invoke(MethodInvocation invocation) throws Throwable {
37-
this.lock.lock();
38-
try {
39-
return invocation.proceed();
40-
}
41-
finally {
42-
this.lock.unlock();
43-
}
32+
public synchronized Object invoke(MethodInvocation invocation) throws Throwable {
33+
return invocation.proceed();
4434
}
4535

4636
}

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/lock/JdbcLockRegistryDelegateTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testLessAmountOfUnlockThanLock() {
6363

6464
final Lock lock = registry.obtain("foo");
6565
for (int i = 0; i < lockCount; i++) {
66-
lock.lock();
66+
lock.tryLock();
6767
}
6868
for (int i = 0; i < unlockCount; i++) {
6969
lock.unlock();
@@ -79,7 +79,7 @@ public void testSameAmountOfUnlockThanLock() {
7979

8080
final Lock lock = registry.obtain("foo");
8181
for (int i = 0; i < lockCount; i++) {
82-
lock.lock();
82+
lock.tryLock();
8383
}
8484
for (int i = 0; i < lockCount; i++) {
8585
lock.unlock();
@@ -91,7 +91,7 @@ public void testSameAmountOfUnlockThanLock() {
9191
@Test
9292
public void testTransientDataAccessException() {
9393
final Lock lock = registry.obtain("foo");
94-
lock.lock();
94+
lock.tryLock();
9595

9696
final AtomicBoolean shouldThrow = new AtomicBoolean(true);
9797
doAnswer(invocation -> {
@@ -109,7 +109,7 @@ public void testTransientDataAccessException() {
109109
@Test
110110
public void testTransactionTimedOutException() {
111111
final Lock lock = registry.obtain("foo");
112-
lock.lock();
112+
lock.tryLock();
113113

114114
final AtomicBoolean shouldThrow = new AtomicBoolean(true);
115115
doAnswer(invocation -> {
@@ -127,7 +127,7 @@ public void testTransactionTimedOutException() {
127127
@Test
128128
public void testTransactionSystemException() {
129129
final Lock lock = registry.obtain("foo");
130-
lock.lock();
130+
lock.tryLock();
131131

132132
final AtomicBoolean shouldThrow = new AtomicBoolean(true);
133133
doAnswer(invocation -> {
Lines changed: 6 additions & 24 deletions
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-2019 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.
@@ -20,8 +20,6 @@
2020
import java.util.concurrent.BlockingQueue;
2121
import java.util.concurrent.LinkedBlockingQueue;
2222
import java.util.concurrent.TimeUnit;
23-
import java.util.concurrent.locks.Lock;
24-
import java.util.concurrent.locks.ReentrantLock;
2523

2624
import org.apache.commons.logging.Log;
2725
import org.apache.commons.logging.LogFactory;
@@ -31,8 +29,6 @@
3129
/**
3230
*
3331
* @author Gunnar Hillert
34-
* @author Christian Tzolov
35-
*
3632
* @since 2.2
3733
*
3834
*/
@@ -42,27 +38,13 @@ public final class Consumer {
4238

4339
private static final BlockingQueue<Message<Collection<?>>> MESSAGES = new LinkedBlockingQueue<Message<Collection<?>>>();
4440

45-
private final Lock lock = new ReentrantLock();
46-
47-
public void receive(Message<Collection<?>> message) {
48-
this.lock.lock();
49-
try {
50-
logger.info("Service Activator received Message: " + message);
51-
MESSAGES.add(message);
52-
}
53-
finally {
54-
this.lock.unlock();
55-
}
41+
public synchronized void receive(Message<Collection<?>> message) {
42+
logger.info("Service Activator received Message: " + message);
43+
MESSAGES.add(message);
5644
}
5745

58-
public Message<Collection<?>> poll(long timeoutInMillis) throws InterruptedException {
59-
this.lock.lock();
60-
try {
61-
return MESSAGES.poll(timeoutInMillis, TimeUnit.MILLISECONDS);
62-
}
63-
finally {
64-
this.lock.unlock();
65-
}
46+
public synchronized Message<Collection<?>> poll(long timeoutInMillis) throws InterruptedException {
47+
return MESSAGES.poll(timeoutInMillis, TimeUnit.MILLISECONDS);
6648
}
6749

6850
}

spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/AbstractMqttClientManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public abstract class AbstractMqttClientManager<T, C> implements ClientManager<T
5050

5151
private static final int DEFAULT_MANAGER_PHASE = 0;
5252

53-
private final Lock lock = new ReentrantLock();
53+
protected final Lock lock = new ReentrantLock();
5454

5555
private final Set<ConnectCallback> connectCallbacks = Collections.synchronizedSet(new HashSet<>());
5656

spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/Mqttv3ClientManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public class Mqttv3ClientManager
4747
extends AbstractMqttClientManager<IMqttAsyncClient, MqttConnectOptions>
4848
implements MqttCallbackExtended {
4949

50-
private final Lock lock = new ReentrantLock();
51-
5250
private final MqttConnectOptions connectionOptions;
5351

5452
private MqttClientPersistence persistence;

spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/core/Mqttv5ClientManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public class Mqttv5ClientManager
4949
extends AbstractMqttClientManager<IMqttAsyncClient, MqttConnectionOptions>
5050
implements MqttCallback {
5151

52-
private final Lock lock = new ReentrantLock();
53-
5452
private final MqttConnectionOptions connectionOptions;
5553

5654
private MqttClientPersistence persistence;

0 commit comments

Comments
 (0)