Reputation: 2021
I have simple OSGI event listener class
@Component(immediate = true)
@Service(value = { EventHandler.class, JobConsumer.class })
@Properties(value = {
@Property(name = JobConsumer.PROPERTY_TOPICS, value = {
TestEventHandler.JOB_TOPICS }),
@Property(name = EventConstants.EVENT_TOPIC, value = { PageEvent.EVENT_TOPIC }) })
public class TestEventHandler implements EventHandler, JobConsumer {
@Override
public void handleEvent(final org.osgi.service.event.Event event)
{
// Create job based on some complex condition
jobManager.createJob(JOB_TOPICS).properties(properties).add();
}
@Override
public JobResult process(Job job) {
// Process job based on parameter in handleEvent function
}
}
The handleEvent event is called sometimes but not always. It stopped listening to events suddenly and if I restart the service again in Felix console then it starts working again. There are other custom OSGI event listener which does not have such issue, only this listener has issue.
Can you please tell me
1) Is this happening because of Thread pool size set to 20 in Felix Event Admin OSGI configuration or something else?
2) Do I need to increase Thread size, Async/sync Thread Pool Ratio and Timeout, if yes how can I determine the numbers?
Upvotes: 3
Views: 1413
Reputation: 19606
If an EventHandler takes too long it becomes black listed and will then not receive any more events.
See http://felix.apache.org/documentation/subprojects/apache-felix-event-admin.html
The timeout can be configured and even turned off. Apart from that it is a good practice to use an executor to run long running tasks.
Upvotes: 3