16
16
package org .springframework .data .redis .stream ;
17
17
18
18
import java .time .Duration ;
19
+ import java .util .Optional ;
19
20
import java .util .OptionalInt ;
20
21
import java .util .concurrent .Executor ;
21
22
import java .util .function .Predicate ;
107
108
* @author Christoph Strobl
108
109
* @author Christian Rest
109
110
* @author DongCheol Kim
111
+ * @author Su Ko
110
112
* @param <K> Stream key and Stream field type.
111
113
* @param <V> Stream value type.
112
114
* @since 2.2
@@ -503,12 +505,14 @@ class StreamMessageListenerContainerOptions<K, V extends Record<K, ?>> {
503
505
private final @ Nullable HashMapper <Object , Object , Object > hashMapper ;
504
506
private final ErrorHandler errorHandler ;
505
507
private final Executor executor ;
508
+ private final @ Nullable Integer phase ;
509
+ private final @ Nullable Boolean autoStartup ;
506
510
507
511
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
508
512
private StreamMessageListenerContainerOptions (Duration pollTimeout , @ Nullable Integer batchSize ,
509
513
RedisSerializer <K > keySerializer , RedisSerializer <Object > hashKeySerializer ,
510
514
RedisSerializer <Object > hashValueSerializer , @ Nullable Class <?> targetType ,
511
- @ Nullable HashMapper <V , ?, ?> hashMapper , ErrorHandler errorHandler , Executor executor ) {
515
+ @ Nullable HashMapper <V , ?, ?> hashMapper , ErrorHandler errorHandler , Executor executor , @ Nullable Integer phase , @ Nullable Boolean autoStartup ) {
512
516
this .pollTimeout = pollTimeout ;
513
517
this .batchSize = batchSize ;
514
518
this .keySerializer = keySerializer ;
@@ -518,6 +522,8 @@ private StreamMessageListenerContainerOptions(Duration pollTimeout, @Nullable In
518
522
this .hashMapper = (HashMapper ) hashMapper ;
519
523
this .errorHandler = errorHandler ;
520
524
this .executor = executor ;
525
+ this .phase = phase ;
526
+ this .autoStartup = autoStartup ;
521
527
}
522
528
523
529
/**
@@ -598,6 +604,21 @@ public Executor getExecutor() {
598
604
return executor ;
599
605
}
600
606
607
+ /**
608
+ * @return the phase.
609
+ * @since 4.0
610
+ */
611
+ public OptionalInt getPhase () {
612
+ return phase != null ? OptionalInt .of (phase ) : OptionalInt .empty ();
613
+ }
614
+
615
+ /**
616
+ * @return the autoStartup.
617
+ * @since 4.0
618
+ */
619
+ public Optional <Boolean > isAutoStartup () {
620
+ return autoStartup != null ? Optional .of (autoStartup ) : Optional .empty ();
621
+ }
601
622
}
602
623
603
624
/**
@@ -618,6 +639,8 @@ class StreamMessageListenerContainerOptionsBuilder<K, V extends Record<K, ?>> {
618
639
private @ Nullable Class <?> targetType ;
619
640
private ErrorHandler errorHandler = LoggingErrorHandler .INSTANCE ;
620
641
private Executor executor = new SimpleAsyncTaskExecutor ();
642
+ private @ Nullable Integer phase ;
643
+ private @ Nullable Boolean autoStartup ;
621
644
622
645
@ SuppressWarnings ("NullAway" )
623
646
private StreamMessageListenerContainerOptionsBuilder () {}
@@ -679,6 +702,28 @@ public StreamMessageListenerContainerOptionsBuilder<K, V> errorHandler(ErrorHand
679
702
return this ;
680
703
}
681
704
705
+ /**
706
+ * Configure a phase for the {@link SmartLifecycle}
707
+ *
708
+ * @return {@code this} {@link StreamMessageListenerContainerOptionsBuilder}.
709
+ * @since 4.0
710
+ */
711
+ public StreamMessageListenerContainerOptionsBuilder <K , V > phase (int phase ) {
712
+ this .phase = phase ;
713
+ return this ;
714
+ }
715
+
716
+ /**
717
+ * Configure a autoStartup for the {@link SmartLifecycle}
718
+ *
719
+ * @return {@code this} {@link StreamMessageListenerContainerOptionsBuilder}.
720
+ * @since 4.0
721
+ */
722
+ public StreamMessageListenerContainerOptionsBuilder <K , V > autoStartup (boolean autoStartup ) {
723
+ this .autoStartup = autoStartup ;
724
+ return this ;
725
+ }
726
+
682
727
/**
683
728
* Configure a key, hash key and hash value serializer.
684
729
*
@@ -796,7 +841,7 @@ public StreamMessageListenerContainerOptions<K, V> build() {
796
841
Assert .notNull (hashValueSerializer , "Hash Value Serializer must not be null" );
797
842
798
843
return new StreamMessageListenerContainerOptions <>(pollTimeout , batchSize , keySerializer , hashKeySerializer ,
799
- hashValueSerializer , targetType , hashMapper , errorHandler , executor );
844
+ hashValueSerializer , targetType , hashMapper , errorHandler , executor , phase , autoStartup );
800
845
}
801
846
802
847
}
0 commit comments