Class PollingSource<T,A>
- Type Parameters:
T- the generic type for the generated message's payloadA- the generic type for the generated message's attributes
Source which automatically handles polling, idempotency and watermarking. As a result of the poll,
many items can be obtained and dispatched for execution, each one as a standalone Message.
The SDK will automatically add a <scheduling-strategy> parameter and the runtime will use that strategy to
automatically schedule executions of the poll(PollContext) method. The PollContext will be used to dispatch
the obtained items, optionally enabling features like watermarking and idempotency.
- Since:
- 1.1
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voiddoStart()Implement this method to perform custom starting logic.protected abstract voiddoStop()Implement this method to perform custom stopping logic.abstract voidonRejectedItem(Result<T, A> result, SourceCallbackContext callbackContext) If one of the items dispatched throughPollContext.accept(Consumer)were rejected (either by watermarking, idempotency, server overload, etc.), this method is to be used to released any resources associated to the givenresult.final voidonStart(SourceCallback<T, A> sourceCallback) This method will be invoked by the runtime to make the source start producing messages.final voidonStop()This method will be invoked by the runtime to make the source stop producing messages.abstract voidpoll(PollContext<T, A> pollContext) This method is responsible for obtaining the items to be dispatched and communicate them through thepollContextusing thePollContext.accept(Consumer)method.
-
Field Details
-
OS_NAME_PREFIX
- See Also:
-
OS_NAME_MASK
- See Also:
-
WATERMARK_OS_NAME_SUFFIX
- See Also:
-
RECENTLY_PROCESSED_IDS_OS_NAME_SUFFIX
- See Also:
-
IDS_ON_UPDATED_WATERMARK_OS_NAME_SUFFIX
- See Also:
-
WATERMARK_ITEM_OS_KEY
- See Also:
-
UPDATED_WATERMARK_ITEM_OS_KEY
- See Also:
-
-
Constructor Details
-
PollingSource
public PollingSource()
-
-
Method Details
-
onStart
public final void onStart(SourceCallback<T, A> sourceCallback) throws org.mule.runtime.api.exception.MuleExceptionThis method will be invoked by the runtime to make the source start producing messages.Each generated message will be passed back to the runtime through the given
sourceCallbackfor processing.This method should throw an exception if the source fails to start, but any other exception encountered during the process of generating messages, should be communicated to the runtime through the
SourceCallback.onConnectionException(ConnectionException)} method.Only the runtime should invoke this method. Do not do it manually
- Specified by:
onStartin classSource<T,A> - Parameters:
sourceCallback- aSourceCallback- Throws:
org.mule.runtime.api.exception.MuleException- If the source fails to start.
-
onStop
public final void onStop()This method will be invoked by the runtime to make the source stop producing messages.This method should not fail. Any exceptions found during the stop process should be logged and correctly handled by the source, but after invoking this method the source must:
- Stop producing messages
- Free any allocated resources
- Be capable of being restarted
Only the runtime should invoke this method. Do not do it manually
-
doStart
protected abstract void doStart() throws org.mule.runtime.api.exception.MuleExceptionImplement this method to perform custom starting logic. Remember that the runtime is polling automatically- Throws:
org.mule.runtime.api.exception.MuleException
-
doStop
protected abstract void doStop()Implement this method to perform custom stopping logic. -
poll
This method is responsible for obtaining the items to be dispatched and communicate them through thepollContextusing thePollContext.accept(Consumer)method.See the
PollContextdocumentation for more information on how to use it and the options available- Parameters:
pollContext- the polling context
-
onRejectedItem
If one of the items dispatched throughPollContext.accept(Consumer)were rejected (either by watermarking, idempotency, server overload, etc.), this method is to be used to released any resources associated to the givenresult.- Parameters:
result- a rejected itemcallbackContext- the associatedSourceCallbackContext
-