To create a Polling Source, you need to add the Source class to the @Sources annotation on the extension class, just like regular Sources. For a Source
to behave as a PollingSource, instead of extending the class Source<T,A>, the class needs to extend from PollingSource<T, A>.
When extending from PollingSource<T, A>, you need to implement the methods poll and onRejectedItem.
-
poll is responsible for obtaining the items to be dispatched and communicating with them through the pollContext using the accept method.
-
onRejectedItem is called when one of the dispatch items was rejected (for example, by watermarking idempotency or server overload). This method is called to release any resources associated with the result set for the PollItem.
Here is an example of the declaration of these methods on the directory listener
implementation for the FTP connector:
public class FtpDirectoryListener extends PollingSource<InputStream, FtpFileAttributes> {
// ...
@Override
public void poll(PollContext<InputStream, FtpFileAttributes> pollContext) {
// ...
}
@Override
public void onRejectedItem(Result<InputStream, FtpFileAttributes> result, SourceCallbackContext callbackContext) {
// ...
}
// ...
}