Skip to content

Commit 25a6981

Browse files
committed
Polishing.
Reformat code. See #2831
1 parent 75e51f5 commit 25a6981

File tree

1 file changed

+26
-40
lines changed

1 file changed

+26
-40
lines changed

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java

+26-40
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.connection.lettuce;
1717

18-
import static org.springframework.data.redis.connection.lettuce.LettuceConnection.CODEC;
19-
import static org.springframework.data.redis.connection.lettuce.LettuceConnection.PipeliningFlushPolicy;
18+
import static org.springframework.data.redis.connection.lettuce.LettuceConnection.*;
2019

2120
import io.lettuce.core.AbstractRedisClient;
2221
import io.lettuce.core.ClientOptions;
@@ -50,6 +49,7 @@
5049

5150
import org.apache.commons.logging.Log;
5251
import org.apache.commons.logging.LogFactory;
52+
5353
import org.springframework.beans.factory.DisposableBean;
5454
import org.springframework.beans.factory.InitializingBean;
5555
import org.springframework.context.SmartLifecycle;
@@ -59,23 +59,10 @@
5959
import org.springframework.data.redis.ExceptionTranslationStrategy;
6060
import org.springframework.data.redis.PassThroughExceptionTranslationStrategy;
6161
import org.springframework.data.redis.RedisConnectionFailureException;
62-
import org.springframework.data.redis.connection.ClusterCommandExecutor;
63-
import org.springframework.data.redis.connection.ClusterTopologyProvider;
64-
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
65-
import org.springframework.data.redis.connection.RedisClusterConfiguration;
66-
import org.springframework.data.redis.connection.RedisClusterConnection;
67-
import org.springframework.data.redis.connection.RedisConfiguration;
62+
import org.springframework.data.redis.connection.*;
6863
import org.springframework.data.redis.connection.RedisConfiguration.ClusterConfiguration;
6964
import org.springframework.data.redis.connection.RedisConfiguration.WithDatabaseIndex;
7065
import org.springframework.data.redis.connection.RedisConfiguration.WithPassword;
71-
import org.springframework.data.redis.connection.RedisConnection;
72-
import org.springframework.data.redis.connection.RedisConnectionFactory;
73-
import org.springframework.data.redis.connection.RedisPassword;
74-
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
75-
import org.springframework.data.redis.connection.RedisSentinelConnection;
76-
import org.springframework.data.redis.connection.RedisSocketConfiguration;
77-
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
78-
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
7966
import org.springframework.data.redis.util.RedisAssertions;
8067
import org.springframework.data.util.Optionals;
8168
import org.springframework.lang.Nullable;
@@ -85,7 +72,8 @@
8572
import org.springframework.util.StringUtils;
8673

8774
/**
88-
* {@link RedisConnectionFactory Connection factory} creating <a href="https://lettuce.io/">Lettuce</a>-based connections.
75+
* {@link RedisConnectionFactory Connection factory} creating <a href="https://lettuce.io/">Lettuce</a>-based
76+
* connections.
8977
* <p>
9078
* This factory creates a new {@link LettuceConnection} on each call to {@link #getConnection()}. While multiple
9179
* {@link LettuceConnection}s share a single thread-safe native connection by default, {@link LettuceConnection} and its
@@ -676,7 +664,7 @@ public AbstractRedisClient getNativeClient() {
676664
public AbstractRedisClient getRequiredNativeClient() {
677665

678666
return RedisAssertions.requireState(getNativeClient(),
679-
"Client not yet initialized; Did you forget to call initialize the bean");
667+
"Client not yet initialized; Did you forget to call initialize the bean");
680668
}
681669

682670
@Nullable
@@ -1006,8 +994,8 @@ public RedisConnection getConnection() {
1006994
return getClusterConnection();
1007995
}
1008996

1009-
LettuceConnection connection =
1010-
doCreateLettuceConnection(getSharedConnection(), this.connectionProvider, getTimeout(), getDatabase());
997+
LettuceConnection connection = doCreateLettuceConnection(getSharedConnection(), this.connectionProvider,
998+
getTimeout(), getDatabase());
1011999

10121000
connection.setConvertPipelineAndTxResults(this.convertPipelineAndTxResults);
10131001

@@ -1145,7 +1133,7 @@ public void resetConnection() {
11451133
doInLock(() -> {
11461134

11471135
Optionals.toStream(Optional.ofNullable(this.connection), Optional.ofNullable(this.reactiveConnection))
1148-
.forEach(SharedConnection::resetConnection);
1136+
.forEach(SharedConnection::resetConnection);
11491137

11501138
this.connection = null;
11511139
this.reactiveConnection = null;
@@ -1255,7 +1243,7 @@ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClie
12551243

12561244
return isStaticMasterReplicaAware() ? createStaticMasterReplicaConnectionProvider((RedisClient) client, codec)
12571245
: isClusterAware() ? createClusterConnectionProvider((RedisClusterClient) client, codec)
1258-
: createStandaloneConnectionProvider((RedisClient) client, codec);
1246+
: createStandaloneConnectionProvider((RedisClient) client, codec);
12591247
}
12601248

12611249
@SuppressWarnings("all")
@@ -1282,8 +1270,7 @@ protected AbstractRedisClient createClient() {
12821270

12831271
return isStaticMasterReplicaAware() ? createStaticMasterReplicaClient()
12841272
: isRedisSentinelAware() ? createSentinelClient()
1285-
: isClusterAware() ? createClusterClient()
1286-
: createBasicClient();
1273+
: isClusterAware() ? createClusterClient() : createBasicClient();
12871274
}
12881275

12891276
private RedisClient createStaticMasterReplicaClient() {
@@ -1349,8 +1336,7 @@ private RedisClusterClient createClusterClient() {
13491336
ClusterConfiguration clusterConfiguration = (ClusterConfiguration) this.configuration;
13501337

13511338
clusterConfiguration.getClusterNodes().stream()
1352-
.map(node -> createRedisURIAndApplySettings(node.getHost(), node.getPort()))
1353-
.forEach(initialUris::add);
1339+
.map(node -> createRedisURIAndApplySettings(node.getHost(), node.getPort())).forEach(initialUris::add);
13541340

13551341
RedisClusterClient clusterClient = this.clientConfiguration.getClientResources()
13561342
.map(clientResources -> RedisClusterClient.create(clientResources, initialUris))
@@ -1403,8 +1389,8 @@ private void assertStarted() {
14031389
switch (current) {
14041390
case CREATED, STOPPED -> throw new IllegalStateException(
14051391
String.format("LettuceConnectionFactory has been %s. Use start() to initialize it", current));
1406-
case DESTROYED -> throw new IllegalStateException(
1407-
"LettuceConnectionFactory was destroyed and cannot be used anymore");
1392+
case DESTROYED ->
1393+
throw new IllegalStateException("LettuceConnectionFactory was destroyed and cannot be used anymore");
14081394
default -> throw new IllegalStateException(String.format("LettuceConnectionFactory is %s", current));
14091395
}
14101396
}
@@ -1435,9 +1421,7 @@ private RedisURI createRedisURIAndApplySettings(String host, int port) {
14351421
private RedisURI createRedisSocketURIAndApplySettings(String socketPath) {
14361422

14371423
return applyAuthentication(RedisURI.Builder.socket(socketPath))
1438-
.withTimeout(this.clientConfiguration.getCommandTimeout())
1439-
.withDatabase(getDatabase())
1440-
.build();
1424+
.withTimeout(this.clientConfiguration.getCommandTimeout()).withDatabase(getDatabase()).build();
14411425
}
14421426

14431427
private RedisURI.Builder applyAuthentication(RedisURI.Builder builder) {
@@ -1471,7 +1455,10 @@ private long getClientTimeout() {
14711455
}
14721456

14731457
private void doInLock(Runnable runnable) {
1474-
doInLock(() -> { runnable.run(); return null; });
1458+
doInLock(() -> {
1459+
runnable.run();
1460+
return null;
1461+
});
14751462
}
14761463

14771464
private <T> T doInLock(Supplier<T> supplier) {
@@ -1480,8 +1467,7 @@ private <T> T doInLock(Supplier<T> supplier) {
14801467

14811468
try {
14821469
return supplier.get();
1483-
}
1484-
finally {
1470+
} finally {
14851471
this.lock.unlock();
14861472
}
14871473
}
@@ -1543,12 +1529,12 @@ private StatefulConnection<E, E> getNativeConnection() {
15431529
}
15441530

15451531
/**
1546-
* Null-safe operation to evaluate whether the given {@link StatefulConnection connetion}
1547-
* is {@link StatefulConnection#isOpen() open}.
1532+
* Null-safe operation to evaluate whether the given {@link StatefulConnection connetion} is
1533+
* {@link StatefulConnection#isOpen() open}.
15481534
*
15491535
* @param connection {@link StatefulConnection} to evaluate.
1550-
* @return a boolean value indicating whether the given {@link StatefulConnection} is not {@literal null}
1551-
* and is {@link StatefulConnection#isOpen() open}.
1536+
* @return a boolean value indicating whether the given {@link StatefulConnection} is not {@literal null} and is
1537+
* {@link StatefulConnection#isOpen() open}.
15521538
* @see io.lettuce.core.api.StatefulConnection#isOpen()
15531539
*/
15541540
private boolean isOpen(@Nullable StatefulConnection<?, ?> connection) {
@@ -1558,8 +1544,8 @@ private boolean isOpen(@Nullable StatefulConnection<?, ?> connection) {
15581544
/**
15591545
* Validate the {@link StatefulConnection connection}.
15601546
* <p>
1561-
* {@link StatefulConnection Connections} are considered valid if they can send/receive ping packets.
1562-
* Invalid {@link StatefulConnection connections} will be closed and the connection state will be reset.
1547+
* {@link StatefulConnection Connections} are considered valid if they can send/receive ping packets. Invalid
1548+
* {@link StatefulConnection connections} will be closed and the connection state will be reset.
15631549
*/
15641550
void validateConnection() {
15651551

0 commit comments

Comments
 (0)