3

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?

Rakesh
  • 4,264
  • 4
  • 32
  • 58
Pakira
  • 1,951
  • 3
  • 25
  • 54

1 Answers1

3

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.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Thanks for your help, if I understood correctly, if Eventhandler takes longer time than what is specified as timeout then is it considered as blacklisted? If I turn it off then will it have other impact in AEM system and do you suggest not to change the default Thread size? – Pakira Nov 10 '19 at 09:52
  • one more question, in case of executor service what could be the size of Executors.newFixedThreadPool(? ); It should be same as what is specified in Felix Event Admin? – Pakira Nov 10 '19 at 10:08