Class AbstractPollingEndpoint
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.AbstractPollingEndpoint
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Phased
,SmartLifecycle
,ComponentSourceAware
,ExpressionCapable
,NamedComponent
,ManageableLifecycle
,ManageableSmartLifecycle
- Direct Known Subclasses:
PollingConsumer
,SourcePollingChannelAdapter
public abstract class AbstractPollingEndpoint
extends AbstractEndpoint
implements BeanClassLoaderAware
An
AbstractEndpoint
extension for Polling Consumer pattern basics.
The standard polling logic is based on a periodic task scheduling according the provided
Trigger
.
When this endpoint is treated as isReactive()
, a polling logic is turned into a
Flux.generate(java.util.function.Consumer)
and Mono.delay(Duration)
combination based on the
SimpleTriggerContext
state.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, Andreas Baer, Christian Tzolov, Ngoc Nhan
-
Field Summary
FieldsFields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleLock
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add the advice chain to the component that responds toreceiveMessage()
calls.protected void
donePollingTask
(@Nullable Message<?> message) The callback of a received message (if any) after the polling task is done.protected void
doStart()
Subclasses must implement this method with the start behavior.protected void
doStop()
Subclasses must implement this method with the stop behavior.protected ClassLoader
@Nullable MessageChannel
Return the default error channel if the error handler is explicitly provided, and it is aMessagePublishingErrorHandler
.long
protected @Nullable reactor.core.publisher.Flux
<Message<?>> protected @Nullable Object
protected @Nullable String
Return the key under which the resource will be made available as an attribute on theIntegrationResourceHolder
.protected @Nullable Object
Return a resource (MessageSource etc.) to bind when using transaction synchronization.protected Executor
protected abstract void
handleMessage
(Message<?> message) Handle a message.protected boolean
protected boolean
isReceiveOnlyAdvice
(Advice advice) Return true if this advice should be applied only to thereceiveMessage()
operation rather than the whole poll.protected boolean
protected void
messageReceived
(@Nullable IntegrationResourceHolder holder, Message<?> message) protected void
onInit()
Subclasses may implement this for initialization logic.protected abstract @Nullable Message
<?> Obtain the next message (if one is available).void
setAdviceChain
(@Nullable List<Advice> adviceChain) void
setBeanClassLoader
(ClassLoader classLoader) void
setErrorHandler
(@Nullable ErrorHandler errorHandler) void
setMaxMessagesPerPoll
(long maxMessagesPerPoll) Configure a cap for messages to poll from the source per scheduling cycle.protected void
setReceiveMessageSource
(Object source) void
setTaskExecutor
(@Nullable Executor taskExecutor) void
setTransactionSynchronizationFactory
(@Nullable TransactionSynchronizationFactory transactionSynchronizationFactory) void
setTrigger
(@Nullable Trigger trigger) Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
destroy, doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getComponentType
Methods inherited from interface org.springframework.context.SmartLifecycle
isPauseable
-
Field Details
-
DEFAULT_POLLING_PERIOD
public static final long DEFAULT_POLLING_PERIODA default polling period forPeriodicTrigger
.- See Also:
-
-
Constructor Details
-
AbstractPollingEndpoint
public AbstractPollingEndpoint()
-
-
Method Details
-
setTaskExecutor
-
getTaskExecutor
-
isSyncExecutor
protected boolean isSyncExecutor() -
setTrigger
-
setAdviceChain
-
setMaxMessagesPerPoll
Configure a cap for messages to poll from the source per scheduling cycle. A negative number means retrieve unlimited messages until theMessageSource
returnsnull
. Zero means do not poll for any records - it can be considered as pausing if 'maxMessagesPerPoll' is later changed to a non-zero value. The polling cycle may exit earlier if the source returns null for the currentreceive
call.- Parameters:
maxMessagesPerPoll
- the number of messages to poll per schedule.
-
getMaxMessagesPerPoll
public long getMaxMessagesPerPoll() -
setErrorHandler
-
setBeanClassLoader
- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
-
setTransactionSynchronizationFactory
public void setTransactionSynchronizationFactory(@Nullable TransactionSynchronizationFactory transactionSynchronizationFactory) -
getDefaultErrorChannel
Return the default error channel if the error handler is explicitly provided, and it is aMessagePublishingErrorHandler
.- Returns:
- the channel or null.
- Since:
- 4.3
-
getBeanClassLoader
-
isReceiveOnlyAdvice
Return true if this advice should be applied only to thereceiveMessage()
operation rather than the whole poll.- Parameters:
advice
- The advice.- Returns:
- true to only advise the
receive
operation.
-
applyReceiveOnlyAdviceChain
Add the advice chain to the component that responds toreceiveMessage()
calls.- Parameters:
chain
- the advice chainCollection
.
-
isReactive
protected boolean isReactive() -
getPollingFlux
-
getReceiveMessageSource
-
setReceiveMessageSource
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractEndpoint
-
doStart
protected void doStart()Description copied from class:AbstractEndpoint
Subclasses must implement this method with the start behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock
.- Specified by:
doStart
in classAbstractEndpoint
-
messageReceived
-
donePollingTask
The callback of a received message (if any) after the polling task is done. If a transaction is enabled, it is committed at this point.- Parameters:
message
- the message result from the polling task.
-
doStop
protected void doStop()Description copied from class:AbstractEndpoint
Subclasses must implement this method with the stop behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock
.- Specified by:
doStop
in classAbstractEndpoint
-
receiveMessage
Obtain the next message (if one is available). MAY return null if no message is immediately available.- Returns:
- The message or null.
-
handleMessage
Handle a message.- Parameters:
message
- The message.
-
getResourceToBind
Return a resource (MessageSource etc.) to bind when using transaction synchronization.- Returns:
- The resource, or null if transaction synchronization is not required.
-
getResourceKey
Return the key under which the resource will be made available as an attribute on theIntegrationResourceHolder
. The defaultExpressionEvaluatingTransactionSynchronizationProcessor
makes this attribute available as a variable in SpEL expressions.- Returns:
- The key, or null (default) if the resource shouldn't be made available as an attribute.
-