Skip to content

Commit f3d3694

Browse files
onobcartembilan
authored andcommitted
GH-3506: No array for poller messaging anns attr
Fixes #3506 Revise the `@Poller` usage in the messaging annotations from an array value to a single entry with a `ValueConstants.DEFAULT_NONE` for default value Code review feedback - Make annotation utils check for NONE more generic - Move docs to whats-new.adoc - Polish javadoc Code review feedback - simplify docs - simplify isProvided checks
1 parent ecb9ac3 commit f3d3694

File tree

15 files changed

+90
-67
lines changed

15 files changed

+90
-67
lines changed

spring-integration-core/src/main/java/org/springframework/integration/annotation/Aggregator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
* @author Marius Bogoevici
3535
* @author Oleg Zhurakousky
3636
* @author Artem Bilan
37+
* @author Chris Bono
3738
*/
3839
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
3940
@Retention(RetentionPolicy.RUNTIME)
@@ -105,10 +106,9 @@
105106
/**
106107
* @return the {@link Poller} options for a polled endpoint
107108
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
108-
* This attribute is an {@code array} just to allow an empty default (no poller).
109109
* Mutually exclusive with {@link #reactive()}.
110110
*/
111-
Poller[] poller() default { };
111+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
112112

113113
/**
114114
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/BridgeFrom.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
3838
* is used as the {@code outputChannel} of the {@link org.springframework.integration.handler.BridgeHandler}.
3939
*
4040
* @author Artem Bilan
41+
* @author Chris Bono
4142
*
4243
* @since 4.0
4344
*/
@@ -70,10 +71,9 @@
7071
/**
7172
* @return the {@link Poller} options for a polled endpoint
7273
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
73-
* This attribute is an {@code array} just to allow an empty default (no poller).
7474
* Mutually exclusive with {@link #reactive()}.
7575
*/
76-
Poller[] poller() default { };
76+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
7777

7878
/**
7979
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/BridgeTo.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@
4343
* If no output channel is provided and no reply-channel exists, an exception is thrown.
4444
*
4545
* @author Artem Bilan
46+
* @author Chris Bono
4647
*
4748
* @since 4.0
4849
*/
@@ -77,10 +78,9 @@
7778
/**
7879
* @return the {@link Poller} options for a polled endpoint
7980
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
80-
* This attribute is an {@code array} just to allow an empty default (no poller).
8181
* Mutually exclusive with {@link #reactive()}.
8282
*/
83-
Poller[] poller() default { };
83+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
8484

8585
/**
8686
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/Filter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@
4040
* @author Mark Fisher
4141
* @author Gary Russell
4242
* @author Artem Bilan
43+
* @author Chris Bono
4344
*
4445
* @since 2.0
4546
*/
@@ -128,10 +129,9 @@
128129
/**
129130
* @return the {@link Poller} options for a polled endpoint
130131
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
131-
* This attribute is an {@code array} just to allow an empty default (no poller).
132132
* Mutually exclusive with {@link #reactive()}.
133133
*/
134-
Poller[] poller() default { };
134+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
135135

136136
/**
137137
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/InboundChannelAdapter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import java.lang.annotation.Target;
2424

2525
import org.springframework.core.annotation.AliasFor;
26+
import org.springframework.messaging.handler.annotation.ValueConstants;
2627

2728
/**
2829
* Indicates that a method is capable of producing a {@link org.springframework.messaging.Message}
@@ -45,6 +46,7 @@
4546
*
4647
* @author Artem Bilan
4748
* @author Gary Russell
49+
* @author Chris Bono
4850
*
4951
* @since 4.0
5052
*/
@@ -86,10 +88,8 @@
8688
/**
8789
* @return the {@link org.springframework.integration.annotation.Poller} options for a polled endpoint
8890
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
89-
* This attribute is an {@code array} just to allow an empty default (no poller).
90-
* Only one {@link org.springframework.integration.annotation.Poller} element is allowed.
9191
* NOTE: a {@link Poller} here has {@link Poller#maxMessagesPerPoll()} set to 1 by default.
9292
*/
93-
Poller[] poller() default { };
93+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
9494

9595
}

spring-integration-core/src/main/java/org/springframework/integration/annotation/Router.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
*
4646
* @author Mark Fisher
4747
* @author Artem Bilan
48+
* @author Chris Bono
4849
*/
4950
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
5051
@Retention(RetentionPolicy.RUNTIME)
@@ -151,10 +152,9 @@
151152
/**
152153
* @return the {@link Poller} options for a polled endpoint
153154
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
154-
* This attribute is an {@code array} just to allow an empty default (no poller).
155155
* Mutually exclusive with {@link #reactive()}.
156156
*/
157-
Poller[] poller() default { };
157+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
158158

159159
/**
160160
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/ServiceActivator.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@
4343
* @author Gary Russell
4444
* @author Artem Bilan
4545
* @author Yilin Wei
46+
* @author Chris Bono
4647
*/
4748
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
4849
@Retention(RetentionPolicy.RUNTIME)
@@ -121,11 +122,9 @@
121122
/**
122123
* @return the {@link Poller} options for a polled endpoint
123124
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
124-
* This attribute is an {@code array} just to allow an empty default (no poller).
125-
* Only one {@link Poller} element is allowed.
126125
* Mutually exclusive with {@link #reactive()}.
127126
*/
128-
Poller[] poller() default { };
127+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
129128

130129
/**
131130
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/Splitter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@
4343
* @author Mark Fisher
4444
* @author Gary Russell
4545
* @author Artem Bilan
46+
* @author Chris Bono
4647
*/
4748
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
4849
@Retention(RetentionPolicy.RUNTIME)
@@ -116,10 +117,9 @@
116117
/**
117118
* @return the {@link Poller} options for a polled endpoint
118119
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
119-
* This attribute is an {@code array} just to allow an empty default (no poller).
120120
* Mutually exclusive with {@link #reactive()}.
121121
*/
122-
Poller[] poller() default { };
122+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
123123

124124
/**
125125
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/annotation/Transformer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
* @author Mark Fisher
3232
* @author Gary Russell
3333
* @author Artem Bilan
34+
* @author Chris Bono
3435
*/
3536
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
3637
@Retention(RetentionPolicy.RUNTIME)
@@ -92,10 +93,9 @@
9293
/**
9394
* @return the {@link Poller} options for a polled endpoint
9495
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
95-
* This attribute is an {@code array} just to allow an empty default (no poller).
9696
* Mutually exclusive with {@link #reactive()}.
9797
*/
98-
Poller[] poller() default { };
98+
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);
9999

100100
/**
101101
* @return the {@link Reactive} marker for a consumer endpoint.

spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,7 +84,6 @@
8484
import org.springframework.messaging.SubscribableChannel;
8585
import org.springframework.messaging.core.DestinationResolutionException;
8686
import org.springframework.messaging.core.DestinationResolver;
87-
import org.springframework.messaging.handler.annotation.ValueConstants;
8887
import org.springframework.scheduling.Trigger;
8988
import org.springframework.scheduling.support.CronTrigger;
9089
import org.springframework.scheduling.support.PeriodicTrigger;
@@ -103,6 +102,7 @@
103102
* @author Mark Fisher
104103
* @author Artem Bilan
105104
* @author Gary Russell
105+
* @author Chris Bono
106106
*/
107107
public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation>
108108
implements MethodAnnotationPostProcessor<T> {
@@ -363,24 +363,24 @@ protected AbstractEndpoint createEndpoint(MessageHandler handler, @SuppressWarni
363363
protected AbstractEndpoint doCreateEndpoint(MessageHandler handler, MessageChannel inputChannel,
364364
List<Annotation> annotations) {
365365

366-
Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class);
366+
Poller poller = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller.class);
367+
367368
Reactive reactive = MessagingAnnotationUtils.resolveAttribute(annotations, "reactive", Reactive.class);
368-
boolean reactiveProvided = reactive != null && !ValueConstants.DEFAULT_NONE.equals(reactive.value());
369369

370-
Assert.state(!reactiveProvided || ObjectUtils.isEmpty(pollers),
370+
Assert.state(reactive == null || poller == null,
371371
"The 'poller' and 'reactive' are mutually exclusive.");
372372

373-
if (inputChannel instanceof Publisher || handler instanceof ReactiveMessageHandlerAdapter || reactiveProvided) {
374-
return reactiveStreamsConsumer(inputChannel, handler, reactiveProvided ? reactive : null);
373+
if (inputChannel instanceof Publisher || handler instanceof ReactiveMessageHandlerAdapter || reactive != null) {
374+
return reactiveStreamsConsumer(inputChannel, handler, reactive);
375375
}
376376
else if (inputChannel instanceof SubscribableChannel) {
377-
Assert.state(ObjectUtils.isEmpty(pollers), () ->
377+
Assert.state(poller == null, () ->
378378
"A '@Poller' should not be specified for Annotation-based " +
379379
"endpoint, since '" + inputChannel + "' is a SubscribableChannel (not pollable).");
380380
return new EventDrivenConsumer((SubscribableChannel) inputChannel, handler);
381381
}
382382
else if (inputChannel instanceof PollableChannel) {
383-
return pollingConsumer(inputChannel, handler, pollers);
383+
return pollingConsumer(inputChannel, handler, poller);
384384
}
385385
else {
386386
throw new IllegalArgumentException("Unsupported 'inputChannel' type: '"
@@ -414,19 +414,15 @@ private ReactiveStreamsConsumer reactiveStreamsConsumer(MessageChannel channel,
414414
return reactiveStreamsConsumer;
415415
}
416416

417-
private PollingConsumer pollingConsumer(MessageChannel inputChannel, MessageHandler handler, Poller[] pollers) {
417+
private PollingConsumer pollingConsumer(MessageChannel inputChannel, MessageHandler handler, Poller poller) {
418418
PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) inputChannel, handler);
419-
configurePollingEndpoint(pollingConsumer, pollers);
419+
configurePollingEndpoint(pollingConsumer, poller);
420420
return pollingConsumer;
421421
}
422422

423-
protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint, Poller[] pollers) {
423+
protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint, Poller poller) {
424424
PollerMetadata pollerMetadata;
425-
if (!ObjectUtils.isEmpty(pollers)) {
426-
Assert.state(pollers.length == 1,
427-
"The 'poller' for an Annotation-based endpoint can have only one '@Poller'.");
428-
Poller poller = pollers[0];
429-
425+
if (poller != null) {
430426
String ref = poller.value();
431427
String triggerRef = poller.trigger();
432428
String executorRef = poller.taskExecutor();

spring-integration-core/src/main/java/org/springframework/integration/config/annotation/InboundChannelAdapterAnnotationPostProcessor.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@
4444
* @author Artem Bilan
4545
* @author Gary Russell
4646
* @author Oleg Zhurakousky
47+
* @author Chris Bono
4748
*
4849
* @since 4.0
4950
*/
@@ -82,8 +83,8 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
8283
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
8384
adapter.setOutputChannelName(channelName);
8485
adapter.setSource(messageSource);
85-
Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class);
86-
configurePollingEndpoint(adapter, pollers);
86+
Poller poller = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller.class);
87+
configurePollingEndpoint(adapter, poller);
8788

8889
return adapter;
8990
}

0 commit comments

Comments
 (0)