java.lang.Object
org.mule.runtime.extension.api.runtime.source.Source<T,A>
org.mule.runtime.extension.api.runtime.source.PollingSource<T,A>
Type Parameters:
T - the generic type for the generated message's payload
A - the generic type for the generated message's attributes

@MinMuleVersion("4.1") public abstract class PollingSource<T,A> extends Source<T,A>
A Special kind of 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 &lt;scheduling-strategy&gt; 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 Details

  • Constructor Details

    • PollingSource

      public PollingSource()
  • Method Details

    • onStart

      public final void onStart(SourceCallback<T,A> sourceCallback) throws org.mule.runtime.api.exception.MuleException
      This 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 sourceCallback for 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:
      onStart in class Source<T,A>
      Parameters:
      sourceCallback - a SourceCallback
      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

      Specified by:
      onStop in class Source<T,A>
    • doStart

      protected abstract void doStart() throws org.mule.runtime.api.exception.MuleException
      Implement 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

      public abstract void poll(PollContext<T,A> pollContext)
      This method is responsible for obtaining the items to be dispatched and communicate them through the pollContext using the PollContext.accept(Consumer) method.

      See the PollContext documentation for more information on how to use it and the options available

      Parameters:
      pollContext - the polling context
    • onRejectedItem

      public abstract void onRejectedItem(Result<T,A> result, SourceCallbackContext callbackContext)
      If one of the items dispatched through PollContext.accept(Consumer) were rejected (either by watermarking, idempotency, server overload, etc.), this method is to be used to released any resources associated to the given result.
      Parameters:
      result - a rejected item
      callbackContext - the associated SourceCallbackContext