Created
March 24, 2013 22:51
-
-
Save arthurtsang/5233947 to your computer and use it in GitHub Desktop.
Maintain a list of service dependiency using OsgiBundleApplicationContextListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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