Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arthurtsang/5233947 to your computer and use it in GitHub Desktop.
Save arthurtsang/5233947 to your computer and use it in GitHub Desktop.
Maintain a list of service dependiency using OsgiBundleApplicationContextListener
@Override
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {
if( event instanceof BootstrappingDependencyEvent) {
BootstrappingDependencyEvent bootstrappingDependencyEvent = (BootstrappingDependencyEvent)event;
OsgiServiceDependencyEvent osgiServiceDependencyEvent = bootstrappingDependencyEvent.getDependencyEvent();
OsgiServiceDependency osgiServiceDependency = osgiServiceDependencyEvent.getServiceDependency();
Bundle bundle = bootstrappingDependencyEvent.getBundle();
BundleId bundleId = new BundleId(bundle.getBundleId(),bundle.getSymbolicName());
BeanId beanId = new BeanId(osgiServiceDependency.getBeanName(),osgiServiceDependency.getServiceFilter().toString());
ServiceStatus status = null;
if( osgiServiceDependencyEvent instanceof OsgiServiceDependencyWaitStartingEvent ) {
status = ServiceStatus.WAITSTARTING;
} else if( osgiServiceDependencyEvent instanceof OsgiServiceDependencyWaitEndedEvent ) {
status = ServiceStatus.WAITENDED;
} else {
status = ServiceStatus.WAITTIMEDOUT;
}
Map<BeanId,ServiceStatus> beanMap = null;
if( statusMap.containsKey(bundleId) ) {
beanMap = statusMap.get(bundleId);
} else {
beanMap = new ConcurrentHashMap<BeanId,ServiceStatus>();
statusMap.put(bundleId,beanMap);
}
beanMap.put(beanId,status);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment