ehcache / ehcache3

Ehcache 3.x line
http://www.ehcache.org
Apache License 2.0
2.02k stars 580 forks source link

Provide OSGi condition which is fulfilled once all required org.ehcache.core.spi.service.ServiceFactory objects are provided #3232

Open kwin opened 5 months ago

kwin commented 5 months ago

If one uses the API outlined in https://www.ehcache.org/documentation/3.9/getting-started.html via CacheManagerBuilder.newCacheManagerBuilder() .build() too early in OSGi runtimes (i.e. when the services of type org.ehcache.core.spi.service.ServiceFactory have not yet been registered) it fails with

ServiceLocator$DependencyException: Failed to find provider with satisfied dependency set for interface org.ehcache.core.events.CacheEventListenerProvider [candidates []]
  at org.ehcache.core.spi.ServiceLocator$DependencySet.build(ServiceLocator.java:350)
  at org.ehcache.core.EhcacheManager.resolveServices(EhcacheManager.java:154) 
  at org.ehcache.core.EhcacheManager.<init>(EhcacheManager.java:125)
  at org.ehcache.core.EhcacheManager.<init>(EhcacheManager.java:115) 
  at org.ehcache.core.EhcacheManager.<init>(EhcacheManager.java:111)
  at com.novonordisk.hcp.integrations.shade.ehcache.config.builders.CacheManagerBuilder.newCacheManager

The above happens with Ehcache 3.9.9 (for other versions the line numbers may differ)

In order to programmatically prevent this race condition, please provide a OSGi condition which is only satisfied once all necessary ServiceFactory service are registered.

kwin commented 5 months ago

This would also require an extension to the documentation at https://www.ehcache.org/documentation/3.9/osgi.html.