Skip to content

Revise @Poller usage to single entry in Messaging Annotations. #3746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,7 @@
* @author Marius Bogoevici
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Chris Bono
*/
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -105,10 +106,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,7 @@
* is used as the {@code outputChannel} of the {@link org.springframework.integration.handler.BridgeHandler}.
*
* @author Artem Bilan
* @author Chris Bono
*
* @since 4.0
*/
Expand Down Expand Up @@ -70,10 +71,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@
* If no output channel is provided and no reply-channel exists, an exception is thrown.
*
* @author Artem Bilan
* @author Chris Bono
*
* @since 4.0
*/
Expand Down Expand Up @@ -77,10 +78,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Chris Bono
*
* @since 2.0
*/
Expand Down Expand Up @@ -128,10 +129,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@
import java.lang.annotation.Target;

import org.springframework.core.annotation.AliasFor;
import org.springframework.messaging.handler.annotation.ValueConstants;

/**
* Indicates that a method is capable of producing a {@link org.springframework.messaging.Message}
Expand All @@ -45,6 +46,7 @@
*
* @author Artem Bilan
* @author Gary Russell
* @author Chris Bono
*
* @since 4.0
*/
Expand Down Expand Up @@ -86,10 +88,8 @@
/**
* @return the {@link org.springframework.integration.annotation.Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Only one {@link org.springframework.integration.annotation.Poller} element is allowed.
* NOTE: a {@link Poller} here has {@link Poller#maxMessagesPerPoll()} set to 1 by default.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,6 +45,7 @@
*
* @author Mark Fisher
* @author Artem Bilan
* @author Chris Bono
*/
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -151,10 +152,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@
* @author Gary Russell
* @author Artem Bilan
* @author Yilin Wei
* @author Chris Bono
*/
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -121,11 +122,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Only one {@link Poller} element is allowed.
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,6 +43,7 @@
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Chris Bono
*/
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -116,10 +117,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
* @author Chris Bono
*/
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
Expand Down Expand Up @@ -92,10 +93,9 @@
/**
* @return the {@link Poller} options for a polled endpoint
* ({@link org.springframework.integration.scheduling.PollerMetadata}).
* This attribute is an {@code array} just to allow an empty default (no poller).
* Mutually exclusive with {@link #reactive()}.
*/
Poller[] poller() default { };
Poller poller() default @Poller(ValueConstants.DEFAULT_NONE);

/**
* @return the {@link Reactive} marker for a consumer endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,6 +103,7 @@
* @author Mark Fisher
* @author Artem Bilan
* @author Gary Russell
* @author Chris Bono
*/
public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation>
implements MethodAnnotationPostProcessor<T> {
Expand Down Expand Up @@ -363,24 +364,26 @@ protected AbstractEndpoint createEndpoint(MessageHandler handler, @SuppressWarni
protected AbstractEndpoint doCreateEndpoint(MessageHandler handler, MessageChannel inputChannel,
List<Annotation> annotations) {

Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class);
Poller poller = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller.class);
boolean pollerProvided = poller != null && !ValueConstants.DEFAULT_NONE.equals(poller.value());

Reactive reactive = MessagingAnnotationUtils.resolveAttribute(annotations, "reactive", Reactive.class);
boolean reactiveProvided = reactive != null && !ValueConstants.DEFAULT_NONE.equals(reactive.value());

Assert.state(!reactiveProvided || ObjectUtils.isEmpty(pollers),
Assert.state(!reactiveProvided || !pollerProvided,
"The 'poller' and 'reactive' are mutually exclusive.");

if (inputChannel instanceof Publisher || handler instanceof ReactiveMessageHandlerAdapter || reactiveProvided) {
return reactiveStreamsConsumer(inputChannel, handler, reactiveProvided ? reactive : null);
}
else if (inputChannel instanceof SubscribableChannel) {
Assert.state(ObjectUtils.isEmpty(pollers), () ->
Assert.state(!pollerProvided, () ->
"A '@Poller' should not be specified for Annotation-based " +
"endpoint, since '" + inputChannel + "' is a SubscribableChannel (not pollable).");
return new EventDrivenConsumer((SubscribableChannel) inputChannel, handler);
}
else if (inputChannel instanceof PollableChannel) {
return pollingConsumer(inputChannel, handler, pollers);
return pollingConsumer(inputChannel, handler, poller);
}
else {
throw new IllegalArgumentException("Unsupported 'inputChannel' type: '"
Expand Down Expand Up @@ -414,19 +417,15 @@ private ReactiveStreamsConsumer reactiveStreamsConsumer(MessageChannel channel,
return reactiveStreamsConsumer;
}

private PollingConsumer pollingConsumer(MessageChannel inputChannel, MessageHandler handler, Poller[] pollers) {
private PollingConsumer pollingConsumer(MessageChannel inputChannel, MessageHandler handler, Poller poller) {
PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) inputChannel, handler);
configurePollingEndpoint(pollingConsumer, pollers);
configurePollingEndpoint(pollingConsumer, poller);
return pollingConsumer;
}

protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint, Poller[] pollers) {
protected void configurePollingEndpoint(AbstractPollingEndpoint pollingEndpoint, Poller poller) {
PollerMetadata pollerMetadata;
if (!ObjectUtils.isEmpty(pollers)) {
Assert.state(pollers.length == 1,
"The 'poller' for an Annotation-based endpoint can have only one '@Poller'.");
Poller poller = pollers[0];

if (poller != null && !ValueConstants.DEFAULT_NONE.equals(poller.value())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DITTO

String ref = poller.value();
String triggerRef = poller.trigger();
String executorRef = poller.taskExecutor();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,6 +44,7 @@
* @author Artem Bilan
* @author Gary Russell
* @author Oleg Zhurakousky
* @author Chris Bono
*
* @since 4.0
*/
Expand Down Expand Up @@ -82,8 +83,8 @@ public Object postProcess(Object bean, String beanName, Method method, List<Anno
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setOutputChannelName(channelName);
adapter.setSource(messageSource);
Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class);
configurePollingEndpoint(adapter, pollers);
Poller poller = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller.class);
configurePollingEndpoint(adapter, poller);

return adapter;
}
Expand Down
Loading