tracker = new ServiceTracker<EventAdmin, EventAdmin>(context, EventAdmin.class.getName(), null);
tracker.open();
}
public void featureEvent(FeatureEvent event) {
EventAdmin eventAdmin = tracker.getService();
if (eventAdmin == null) {
return;
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(EventConstants.TYPE, event.getType());
props.put(EventConstants.EVENT, event);
props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
props.put(EventConstants.FEATURE_NAME, event.getFeature().getName());
props.put(EventConstants.FEATURE_VERSION, event.getFeature().getVersion());
String topic;
switch (event.getType()) {
case FeatureInstalled:
topic = EventConstants.TOPIC_FEATURES_INSTALLED;
break;
case FeatureUninstalled:
topic = EventConstants.TOPIC_FEATURES_UNINSTALLED;
break;
default:
throw new IllegalStateException("Unknown features event type: " + event.getType());
}
eventAdmin.postEvent(new Event(topic, props));
}