Skip to content

Commit b8e52f8

Browse files
committed
Polish "Allow configuring lifecycle in listener containers".
Removes the lifecycle setters from the stream container as it should be configured via the stream options. Also rewords the javadoc comments and moves the autoStartup get/set by the phase get/set. Original Pull Request: #3224 Related tickets: #3208 Signed-off-by: Chris Bono <[email protected]>
1 parent c88d6b1 commit b8e52f8

File tree

3 files changed

+27
-51
lines changed

3 files changed

+27
-51
lines changed

src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,13 @@ public int getPhase() {
627627
return this.phase;
628628
}
629629

630-
/**
631-
* Specify the lifecycle phase for this container.
632-
* Lower values start earlier and stop later.
633-
* The default is {@code Integer.MAX_VALUE}.
634-
*
635-
* @see SmartLifecycle#getPhase()
636-
* @since 4.0
637-
*/
630+
/**
631+
* Configure the lifecycle phase that this listener container is supposed to run in. The default is
632+
* {@code Integer.MAX_VALUE}.
633+
*
634+
* @see org.springframework.context.SmartLifecycle#getPhase()
635+
* @since 4.0
636+
*/
638637
public void setPhase(int phase) {
639638
this.phase = phase;
640639
}
@@ -644,14 +643,13 @@ public boolean isAutoStartup() {
644643
return this.autoStartup;
645644
}
646645

647-
/**
648-
* Configure if this Lifecycle connection factory should get started automatically by the container at the time that
649-
* the containing ApplicationContext gets refreshed.
650-
* The default is {@code true}.
651-
*
652-
* @see SmartLifecycle#isAutoStartup()
653-
* @since 4.0
654-
*/
646+
/**
647+
* Configure if this listener container should get started automatically at the time that the containing
648+
* {@code ApplicationContext} gets refreshed. The default is {@code true}.
649+
*
650+
* @see org.springframework.context.SmartLifecycle#isAutoStartup()
651+
* @since 4.0
652+
*/
655653
public void setAutoStartup(boolean autoStartup) {
656654
this.autoStartup = autoStartup;
657655
}

src/main/java/org/springframework/data/redis/stream/DefaultStreamMessageListenerContainer.java

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DefaultStreamMessageListenerContainer<K, V extends Record<K, ?>> implement
6969
private boolean running = false;
7070

7171
private int phase = Integer.MAX_VALUE;
72-
private boolean autoStartup = false;
72+
private boolean autoStartup;
7373

7474
/**
7575
* Create a new {@link DefaultStreamMessageListenerContainer}.
@@ -95,11 +95,11 @@ class DefaultStreamMessageListenerContainer<K, V extends Record<K, ?>> implement
9595
this.streamOperations = this.template.opsForStream();
9696
}
9797

98-
if(containerOptions.isAutoStartup().isPresent()){
98+
if (containerOptions.isAutoStartup().isPresent()) {
9999
this.autoStartup = containerOptions.isAutoStartup().get();
100100
}
101101

102-
if(containerOptions.getPhase().isPresent()){
102+
if (containerOptions.getPhase().isPresent()) {
103103
this.phase = containerOptions.getPhase().getAsInt();
104104
}
105105
}
@@ -133,23 +133,6 @@ private RedisTemplate<K, V> createRedisTemplate(RedisConnectionFactory connectio
133133
return template;
134134
}
135135

136-
@Override
137-
public boolean isAutoStartup() {
138-
return this.autoStartup;
139-
}
140-
141-
/**
142-
* Configure if this Lifecycle connection factory should get started automatically by the container at the time that
143-
* the containing ApplicationContext gets refreshed.
144-
* The default is {@code false}.
145-
*
146-
* @see org.springframework.context.SmartLifecycle#isAutoStartup()
147-
* @since 4.0
148-
*/
149-
public void setAutoStartup(boolean autoStartup) {
150-
this.autoStartup = autoStartup;
151-
}
152-
153136
@Override
154137
public void stop(Runnable callback) {
155138

@@ -204,17 +187,10 @@ public int getPhase() {
204187
return this.phase;
205188
}
206189

207-
/**
208-
* Specify the lifecycle phase for this container.
209-
* Lower values start earlier and stop later.
210-
* The default is {@code Integer.MAX_VALUE}.
211-
*
212-
* @see org.springframework.context.SmartLifecycle#getPhase()
213-
* @since 4.0
214-
*/
215-
public void setPhase(int phase) {
216-
this.phase = phase;
217-
}
190+
@Override
191+
public boolean isAutoStartup() {
192+
return this.autoStartup;
193+
}
218194

219195
@Override
220196
public Subscription register(StreamReadRequest<K> streamRequest, StreamListener<K, V> listener) {

src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,17 @@ public Executor getExecutor() {
605605
}
606606

607607
/**
608-
* @return the phase.
608+
* @return the configured phase to use for the container lifecycle or {@code empty} if the phase was not
609+
* specified on the options.
609610
* @since 4.0
610611
*/
611612
public OptionalInt getPhase() {
612613
return phase != null ? OptionalInt.of(phase) : OptionalInt.empty();
613614
}
614615

615616
/**
616-
* @return the autoStartup.
617+
* @return the configured autoStartup to use for the container lifecycle or {@code empty} if the autoStartup
618+
* was not specified on the options.
617619
* @since 4.0
618620
*/
619621
public Optional<Boolean> isAutoStartup() {
@@ -703,7 +705,7 @@ public StreamMessageListenerContainerOptionsBuilder<K, V> errorHandler(ErrorHand
703705
}
704706

705707
/**
706-
* Configure a phase for the {@link SmartLifecycle}
708+
* Configure the phase to use for the container {@link SmartLifecycle}
707709
*
708710
* @return {@code this} {@link StreamMessageListenerContainerOptionsBuilder}.
709711
* @since 4.0
@@ -714,7 +716,7 @@ public StreamMessageListenerContainerOptionsBuilder<K, V> phase(int phase) {
714716
}
715717

716718
/**
717-
* Configure a autoStartup for the {@link SmartLifecycle}
719+
* Configure the autoStartup to use for the container {@link SmartLifecycle}
718720
*
719721
* @return {@code this} {@link StreamMessageListenerContainerOptionsBuilder}.
720722
* @since 4.0

0 commit comments

Comments
 (0)