Skip to content

Commit 9fe32d5

Browse files
committed
Polishing.
Refine documentation about auto-startup. Set phase to zero to be in the middle between min and max. See #2635 Original pull request: #2636
1 parent d98afb9 commit 9fe32d5

File tree

2 files changed

+48
-43
lines changed

2 files changed

+48
-43
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactory.java

+26-22
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@
7474
* <li>{@link RedisClusterConfiguration}</li>
7575
* </ul>
7676
* <p>
77-
* This connection factory must be {@link #afterPropertiesSet() initialized} and {@link SmartLifecycle#start() started}
78-
* prior to {@link #getConnection obtaining connections}. You can {@link SmartLifecycle#stop()} and
79-
* {@link SmartLifecycle#start() restart} this connection factory if needed.
77+
* This connection factory implements {@link InitializingBean} and {@link SmartLifecycle} for flexible lifecycle
78+
* control. It must be {@link #afterPropertiesSet() initialized} and {@link #start() started} before you can obtain a
79+
* connection. {@link #afterPropertiesSet() Initialization} {@link SmartLifecycle#start() starts} this bean
80+
* {@link #isAutoStartup() by default}. You can {@link SmartLifecycle#stop()} and {@link SmartLifecycle#start() restart}
81+
* this connection factory if needed.
8082
*
8183
* @author Costin Leau
8284
* @author Thomas Darimont
@@ -96,12 +98,15 @@ public class JedisConnectionFactory
9698

9799
private final JedisClientConfiguration clientConfiguration;
98100

99-
private boolean convertPipelineAndTxResults = true;
100101
private RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration("localhost",
101102
Protocol.DEFAULT_PORT);
102103

103104
private @Nullable RedisConfiguration configuration;
104105

106+
private int phase = 0; // in between min and max values
107+
108+
private boolean convertPipelineAndTxResults = true;
109+
105110
/**
106111
* Lifecycle state of this factory.
107112
*/
@@ -118,8 +123,6 @@ enum State {
118123
private @Nullable ClusterTopologyProvider topologyProvider;
119124
private @Nullable ClusterCommandExecutor clusterCommandExecutor;
120125

121-
private int phase = DEFAULT_PHASE - 10;
122-
123126
/**
124127
* Constructs a new {@link JedisConnectionFactory} instance with default settings (default connection pooling).
125128
*/
@@ -266,7 +269,8 @@ public JedisConnectionFactory(RedisClusterConfiguration clusterConfig, JedisClie
266269
public void afterPropertiesSet() {
267270

268271
clientConfig = createClientConfig(getDatabase(), getRedisUsername(), getRedisPassword());
269-
if(isAutoStartup()) {
272+
273+
if (isAutoStartup()) {
270274
start();
271275
}
272276
}
@@ -368,6 +372,21 @@ public void stop() {
368372
}
369373
}
370374

375+
@Override
376+
public int getPhase() {
377+
return phase;
378+
}
379+
380+
/**
381+
* Specify the lifecycle phase for pausing and resuming this executor. The default is {@code 0}.
382+
*
383+
* @since 3.2
384+
* @see SmartLifecycle#getPhase()
385+
*/
386+
public void setPhase(int phase) {
387+
this.phase = phase;
388+
}
389+
371390
@Override
372391
public boolean isRunning() {
373392
return State.STARTED.equals(state.get());
@@ -859,21 +878,6 @@ public boolean isRedisClusterAware() {
859878
return RedisConfiguration.isClusterConfiguration(configuration);
860879
}
861880

862-
@Override
863-
public int getPhase() {
864-
return phase;
865-
}
866-
867-
/**
868-
* Specify the lifecycle phase for pausing and resuming this executor.
869-
* The default is {@link #DEFAULT_PHASE} - 10.
870-
* @since 3.2
871-
* @see SmartLifecycle#getPhase()
872-
*/
873-
public void setPhase(int phase) {
874-
this.phase = phase;
875-
}
876-
877881
@Override
878882
public RedisSentinelConnection getSentinelConnection() {
879883

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

+22-21
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@
8989
* <li>{@link RedisClusterConfiguration}</li>
9090
* </ul>
9191
* <p>
92-
* This connection factory must be {@link #afterPropertiesSet() initialized} and {@link SmartLifecycle#start() started}
93-
* prior to {@link #getConnection obtaining connections}. You can {@link SmartLifecycle#stop()} and
94-
* {@link SmartLifecycle#start() restart} this connection factory if needed.
92+
* This connection factory implements {@link InitializingBean} and {@link SmartLifecycle} for flexible lifecycle
93+
* control. It must be {@link #afterPropertiesSet() initialized} and {@link #start() started} before you can obtain a
94+
* connection. {@link #afterPropertiesSet() Initialization} {@link SmartLifecycle#start() starts} this bean
95+
* {@link #isAutoStartup() by default}. You can {@link SmartLifecycle#stop()} and {@link SmartLifecycle#start() restart}
96+
* this connection factory if needed.
9597
*
9698
* @author Costin Leau
9799
* @author Jennifer Hickey
@@ -120,6 +122,7 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv
120122
private RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration("localhost", 6379);
121123

122124
private @Nullable RedisConfiguration configuration;
125+
private int phase = 0; // in between min and max values
123126

124127
private boolean validateConnection = false;
125128
private boolean shareNativeConnection = true;
@@ -128,8 +131,6 @@ public class LettuceConnectionFactory implements RedisConnectionFactory, Reactiv
128131

129132
private PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand();
130133

131-
private int phase = DEFAULT_PHASE - 10;
132-
133134
/**
134135
* Lifecycle state of this factory.
135136
*/
@@ -395,14 +396,29 @@ public void stop() {
395396
state.set(State.STOPPED);
396397
}
397398

399+
@Override
400+
public int getPhase() {
401+
return phase;
402+
}
403+
404+
/**
405+
* Specify the lifecycle phase for pausing and resuming this executor. The default is {@code 0}.
406+
*
407+
* @since 3.2
408+
* @see SmartLifecycle#getPhase()
409+
*/
410+
public void setPhase(int phase) {
411+
this.phase = phase;
412+
}
413+
398414
@Override
399415
public boolean isRunning() {
400416
return State.STARTED.equals(state.get());
401417
}
402418

403419
@Override
404420
public void afterPropertiesSet() {
405-
if(isAutoStartup()) {
421+
if (isAutoStartup()) {
406422
start();
407423
}
408424
}
@@ -1101,21 +1117,6 @@ public boolean isClusterAware() {
11011117
return RedisConfiguration.isClusterConfiguration(configuration);
11021118
}
11031119

1104-
@Override
1105-
public int getPhase() {
1106-
return phase;
1107-
}
1108-
1109-
/**
1110-
* Specify the lifecycle phase for pausing and resuming this executor.
1111-
* The default is {@link #DEFAULT_PHASE} - 10.
1112-
* @since 3.2
1113-
* @see SmartLifecycle#getPhase()
1114-
*/
1115-
public void setPhase(int phase) {
1116-
this.phase = phase;
1117-
}
1118-
11191120
/**
11201121
* @return the shared connection using {@literal byte[]} encoding for imperative API use. {@literal null} if
11211122
* {@link #getShareNativeConnection() connection sharing} is disabled or when connected to Redis Cluster.

0 commit comments

Comments
 (0)