I am using Osgi (Karaf) EventAdmin to broadcast data from a change Data Capture thread to some bundles in my OSGI container using post event and I want to stop the thread once there is no consumers for the topic or channel. I started with a simple example and this is how I braodcast the events:
ServiceTracker eventAdminTracker = new ServiceTracker(context, EventAdmin.class.getName(), null);
eventAdminTracker.open();
eventAdmin = (EventAdmin) eventAdminTracker.getService();
cdcEvent.put("DataChange",new String(source, offset, length) );
Event event = new Event(POST_EVENT_QUEUE, cdcEvent);
eventAdmin.postEvent(event);
this the event handler
Dictionary dp = new Hashtable();
dp.put(EventConstants.EVENT_TOPIC, POST_EVENT_QUEUE);
context.registerService(EventHandler.class.getName(), new PostEventHandler(), dp)
....
public class PostEventHandler implements EventHandler{
@Override
public void handleEvent(Event event) {
String value = event.getProperty("DataChange").toString();
System.out.println("value from dataSource : "+value );
}
}
Is there a way to check if there is consumers on a channel or a Queu ?