@@ -135,7 +135,7 @@ public abstract class MessagingMessageListenerAdapter<K, V> implements ConsumerS
135
135
* @param bean the bean.
136
136
* @param method the method.
137
137
*/
138
- public MessagingMessageListenerAdapter (Object bean , Method method ) {
138
+ protected MessagingMessageListenerAdapter (Object bean , Method method ) {
139
139
this .bean = bean ;
140
140
this .inferredType = determineInferredType (method ); // NOSONAR = intentionally not final
141
141
}
@@ -310,35 +310,35 @@ public void setSplitIterables(boolean splitIterables) {
310
310
311
311
@ Override
312
312
public void registerSeekCallback (ConsumerSeekCallback callback ) {
313
- if (this .bean instanceof ConsumerSeekAware ) {
314
- (( ConsumerSeekAware ) this . bean ) .registerSeekCallback (callback );
313
+ if (this .bean instanceof ConsumerSeekAware csa ) {
314
+ csa .registerSeekCallback (callback );
315
315
}
316
316
}
317
317
318
318
@ Override
319
319
public void onPartitionsAssigned (Map <TopicPartition , Long > assignments , ConsumerSeekCallback callback ) {
320
- if (this .bean instanceof ConsumerSeekAware ) {
321
- (( ConsumerSeekAware ) this . bean ) .onPartitionsAssigned (assignments , callback );
320
+ if (this .bean instanceof ConsumerSeekAware csa ) {
321
+ csa .onPartitionsAssigned (assignments , callback );
322
322
}
323
323
}
324
324
325
325
@ Override
326
326
public void onPartitionsRevoked (Collection <TopicPartition > partitions ) {
327
- if (this .bean instanceof ConsumerSeekAware ) {
328
- (( ConsumerSeekAware ) this . bean ) .onPartitionsRevoked (partitions );
327
+ if (this .bean instanceof ConsumerSeekAware csa ) {
328
+ csa .onPartitionsRevoked (partitions );
329
329
}
330
330
}
331
331
332
332
@ Override
333
333
public void onIdleContainer (Map <TopicPartition , Long > assignments , ConsumerSeekCallback callback ) {
334
- if (this .bean instanceof ConsumerSeekAware ) {
335
- (( ConsumerSeekAware ) this . bean ) .onIdleContainer (assignments , callback );
334
+ if (this .bean instanceof ConsumerSeekAware csa ) {
335
+ csa .onIdleContainer (assignments , callback );
336
336
}
337
337
}
338
338
339
- protected Message <?> toMessagingMessage (ConsumerRecord <K , V > record , @ Nullable Acknowledgment acknowledgment ,
339
+ protected Message <?> toMessagingMessage (ConsumerRecord <K , V > cRecord , @ Nullable Acknowledgment acknowledgment ,
340
340
Consumer <?, ?> consumer ) {
341
- return getMessageConverter ().toMessage (record , acknowledgment , consumer , getType ());
341
+ return getMessageConverter ().toMessage (cRecord , acknowledgment , consumer , getType ());
342
342
}
343
343
344
344
/**
@@ -417,8 +417,8 @@ protected void handleResult(Object resultArg, Object request, Object source) {
417
417
@ Nullable
418
418
private String evaluateReplyTopic (Object request , Object source , Object result ) {
419
419
String replyTo = null ;
420
- if (result instanceof InvocationResult ) {
421
- replyTo = evaluateTopic (request , source , result , (( InvocationResult ) result ) .getSendTo ());
420
+ if (result instanceof InvocationResult invResult ) {
421
+ replyTo = evaluateTopic (request , source , result , invResult .getSendTo ());
422
422
}
423
423
else if (this .replyTopicExpression != null ) {
424
424
replyTo = evaluateTopic (request , source , result , this .replyTopicExpression );
@@ -492,7 +492,7 @@ else if (result instanceof Message) {
492
492
}
493
493
}
494
494
495
- private Message <?> checkHeaders (Object result , String topic , Object source ) { // NOSONAR (complexity)
495
+ private Message <?> checkHeaders (Object result , String topic , @ Nullable Object source ) { // NOSONAR (complexity)
496
496
Message <?> reply = (Message <?>) result ;
497
497
MessageHeaders headers = reply .getHeaders ();
498
498
boolean needsTopic = headers .get (KafkaHeaders .TOPIC ) == null ;
@@ -642,8 +642,8 @@ else if (methodParameter.hasParameterAnnotation(Header.class)) {
642
642
allowedBatchParameters ++;
643
643
}
644
644
else {
645
- if (parameterType instanceof ParameterizedType
646
- && (( ParameterizedType ) parameterType ) .getRawType ().equals (Consumer .class )) {
645
+ if (parameterType instanceof ParameterizedType paramType
646
+ && paramType .getRawType ().equals (Consumer .class )) {
647
647
allowedBatchParameters ++;
648
648
}
649
649
}
@@ -672,8 +672,7 @@ else if (methodParameter.hasParameterAnnotation(Header.class)) {
672
672
673
673
private Type extractGenericParameterTypFromMethodParameter (MethodParameter methodParameter ) {
674
674
Type genericParameterType = methodParameter .getGenericParameterType ();
675
- if (genericParameterType instanceof ParameterizedType ) {
676
- ParameterizedType parameterizedType = (ParameterizedType ) genericParameterType ;
675
+ if (genericParameterType instanceof ParameterizedType parameterizedType ) {
677
676
if (parameterizedType .getRawType ().equals (Message .class )) {
678
677
genericParameterType = ((ParameterizedType ) genericParameterType ).getActualTypeArguments ()[0 ];
679
678
}
@@ -684,8 +683,8 @@ else if (parameterizedType.getRawType().equals(List.class)
684
683
this .isConsumerRecordList = paramType .equals (ConsumerRecord .class )
685
684
|| (isSimpleListOfConsumerRecord (paramType )
686
685
|| isListOfConsumerRecordUpperBounded (paramType ));
687
- boolean messageHasGeneric = paramType instanceof ParameterizedType
688
- && (( ParameterizedType ) paramType ) .getRawType ().equals (Message .class );
686
+ boolean messageHasGeneric = paramType instanceof ParameterizedType pType
687
+ && pType .getRawType ().equals (Message .class );
689
688
this .isMessageList = paramType .equals (Message .class ) || messageHasGeneric ;
690
689
if (messageHasGeneric ) {
691
690
genericParameterType = ((ParameterizedType ) paramType ).getActualTypeArguments ()[0 ];
@@ -699,26 +698,23 @@ else if (parameterizedType.getRawType().equals(List.class)
699
698
}
700
699
701
700
private boolean isSimpleListOfConsumerRecord (Type paramType ) {
702
- return paramType instanceof ParameterizedType
703
- && ((ParameterizedType ) paramType ).getRawType ().equals (ConsumerRecord .class );
701
+ return paramType instanceof ParameterizedType pType && pType .getRawType ().equals (ConsumerRecord .class );
704
702
}
705
703
706
704
private boolean isListOfConsumerRecordUpperBounded (Type paramType ) {
707
705
return isWildCardWithUpperBound (paramType )
708
- && ((WildcardType ) paramType ).getUpperBounds ()[0 ] instanceof ParameterizedType
709
- && ((ParameterizedType ) ((WildcardType ) paramType ).getUpperBounds ()[0 ])
710
- .getRawType ().equals (ConsumerRecord .class );
706
+ && ((WildcardType ) paramType ).getUpperBounds ()[0 ] instanceof ParameterizedType wildCardZero
707
+ && wildCardZero .getRawType ().equals (ConsumerRecord .class );
711
708
}
712
709
713
710
private boolean isWildCardWithUpperBound (Type paramType ) {
714
- return paramType instanceof WildcardType
715
- && (( WildcardType ) paramType ) .getUpperBounds () != null
716
- && (( WildcardType ) paramType ) .getUpperBounds ().length > 0 ;
711
+ return paramType instanceof WildcardType wcType
712
+ && wcType .getUpperBounds () != null
713
+ && wcType .getUpperBounds ().length > 0 ;
717
714
}
718
715
719
716
private boolean isMessageWithNoTypeInfo (Type parameterType ) {
720
- if (parameterType instanceof ParameterizedType ) {
721
- ParameterizedType parameterizedType = (ParameterizedType ) parameterType ;
717
+ if (parameterType instanceof ParameterizedType parameterizedType ) {
722
718
Type rawType = parameterizedType .getRawType ();
723
719
if (rawType .equals (Message .class )) {
724
720
return parameterizedType .getActualTypeArguments ()[0 ] instanceof WildcardType ;
@@ -728,8 +724,7 @@ private boolean isMessageWithNoTypeInfo(Type parameterType) {
728
724
}
729
725
730
726
private boolean parameterIsType (Type parameterType , Type type ) {
731
- if (parameterType instanceof ParameterizedType ) {
732
- ParameterizedType parameterizedType = (ParameterizedType ) parameterType ;
727
+ if (parameterType instanceof ParameterizedType parameterizedType ) {
733
728
Type rawType = parameterizedType .getRawType ();
734
729
if (rawType .equals (type )) {
735
730
return true ;
@@ -740,34 +735,12 @@ private boolean parameterIsType(Type parameterType, Type type) {
740
735
741
736
/**
742
737
* Root object for reply expression evaluation.
738
+ * @param request the request.
739
+ * @param source the source.
740
+ * @param result the result.
743
741
* @since 2.0
744
742
*/
745
- public static final class ReplyExpressionRoot {
746
-
747
- private final Object request ;
748
-
749
- private final Object source ;
750
-
751
- private final Object result ;
752
-
753
- public ReplyExpressionRoot (Object request , Object source , Object result ) {
754
- this .request = request ;
755
- this .source = source ;
756
- this .result = result ;
757
- }
758
-
759
- public Object getRequest () {
760
- return this .request ;
761
- }
762
-
763
- public Object getSource () {
764
- return this .source ;
765
- }
766
-
767
- public Object getResult () {
768
- return this .result ;
769
- }
770
-
743
+ public record ReplyExpressionRoot (Object request , Object source , Object result ) {
771
744
}
772
745
773
746
}
0 commit comments