Alberto Coello
Alberto Coello

Reputation: 13

Why start() and poll() in SourceTask are abstract?

start() and poll() are abstract so in my class which extends from SourceTask I can do the following:

public void start(Map<String, String> props, Object anotherParameter)
{
//whatever
}

public List<SourceRecord> poll(Object anotherParameter) throws InterruptedException 
{
//whatever
}

But how does the code invoking 'poll(whateverObject)' or 'start(props, whateverObject)' do initialize the whateverObject and reference it properly when invokating it? Because I can not customize the code which invokes this methods, right? Or can I? And if yes, how?

I have seen other Connectors implementations where this is done but I do not understand how it can work.

Upvotes: 0

Views: 57

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191874

start() and poll() are abstract so in my class which extends from SourceTask I can do the following

No, you cannot "do the following" (add parameters) because those are not the method contracts.

You still need to override the actual methods, but then you could call other methods (of the same name, with parameters), if you needed to, but those wouldn't be abstract, and have no semantic meaning to be overloaded, so they could be named anything, therefore is just regular Java method calling.

I can not customize the code which invokes this methods, right?

You cannot*.

* Unless you want to rebuild Kafka Connect from source

The problem is I don't have the control of how and when poll() is invoked

That is correct. Not really clear what parameters you are trying to add, but poll certainly doesn't need anything and any object initialization you need to do should be done via the configuration (the property map passed to the start method)

Upvotes: 1

Related Questions