I've 2 interfaces and 2 implementations like below.
KafkaConsumerExecutor
(Interface)DefaultExecutor
(Implementation of 1)ConsumerRecordsProcessor
(Interface)LastOnlyRecordsProcessor
(Impl of 3.)
--
public interface KafkaConsumerExecutor {
void start();
void stop();
}
public class DefaultExecutor<MESSAGE_TYPE> implements KafkaConsumerExecutor {
private final ConsumerRecordsProcessor<MESSAGE_TYPE> consumerRecordsProcessor;
@Override
public void start(){}
//processStuff
}
@Override
public void stop(){}
//kill
}
public interface ConsumerRecordsProcessor<MESSAGE_TYPE> {
void process(Iterable<ConsumerRecord<String, MESSAGE_TYPE>> consumerRecords);
}
--
public class LastOnlyRecordsProcessor<MESSAGE_TYPE extends Serializable> implements ConsumerRecordsProcessor<MESSAGE_TYPE> {
public void process(Iterable<ConsumerRecord<String, MESSAGE_TYPE>> consumerRecords){
// process stuff.
}
}
Finally, I have the class where I call start the executor.
@Inject
public KafkaListenerManagerImpl(ConsumerExecutor consumerExecutor) {
this.consumerExecutor= consumerExecutor;
}
And my problem is, I cannot bind my generic implementation DefaultExecutor<String>
to ConsumerExecutor
The ways I tried is;
1.
bind(new TypeLiteral<DefaultExecutor<String>>() {}).to(new TypeLiteral<ConsumerExecutor>(){});
bind(LastOnlyRecordsProcessor.class).to(new TypeLiteral<ConsumerRecordsProcessor<Request>>() {});
This one fails with Caused by: java.lang.IllegalArgumentException: argument type mismatch
2.
bind(DefaultExecutor.class).to(new TypeLiteral<ConsumerExecutor>() {});
bind(LastOnlyRecordsProcessor.class).to(new TypeLiteral<ConsumerRecordsProcessor<String>>() {});
This one looks better , but then It can't find the perspective however then I don't have the binding for Processor.
UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ConsumerRecordsProcessor<MESSAGE_TYPE>,parent=DefaultExecutor,qualifiers={},position=1,optional=false,self=false,unqualified=null,1237264838)
-
bind(DefaultExecutor.class).to(new TypeLiteral<ConsumerExecutor>() {}); bind(new TypeLiteral<LastOnlyRecordsProcessor<String>>() {}).to(new TypeLiteral<ConsumerRecordsProcessor<String>>() {});
Again the same;
Caused by: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ConsumerRecordsProcessor<MESSAGE_TYPE>,parent=DefaultExecutor,qualifiers={},position=1,optional=false,self=false,unqualified=null,202064342)
Question in a nutshell is that,
- I want to bind the DefaultExecutor to ConsumerExecutor.
- LastRecordsOnlyProcessor to ConsumerRecordsProcessor
I don't have much hope, but do you guys see where am I doing wrong?
Thanks in advance.