[JBoss JIRA] (ISPN-3847) Improve resilience of ModuleLifecycle loading
by Paul Ferraro (JIRA)
[ https://issues.jboss.org/browse/ISPN-3847?page=com.atlassian.jira.plugin.... ]
Paul Ferraro updated ISPN-3847:
-------------------------------
Affects Version/s: 6.0.1.Final
(was: 6.0.0.Final)
> Improve resilience of ModuleLifecycle loading
> ---------------------------------------------
>
> Key: ISPN-3847
> URL: https://issues.jboss.org/browse/ISPN-3847
> Project: Infinispan
> Issue Type: Enhancement
> Components: Core API
> Affects Versions: 6.0.1.Final
> Reporter: Paul Ferraro
> Assignee: Mircea Markus
>
> Currently, org.infinispan.util.ModuleProperties.resolveModuleLifecycles(...) uses a ServiceLoader to directly load ModuleLifecycle instances. However, if a jar exists on the classpath containing a META-INF/services/org.infinispan.lifecycle.ModuleLifecycle file, but the class name contained within cannot be loaded, due to, for example, a dependency jar being missing, then the whole resolveModuleLifecycles(...) method chokes due to a ServiceConfigurationError. For example, if infinispan-query is on the classpath, but hibernate-search is not, Infinispan is unusable.
> I can see 2 ways to fix this:
> 1. Use the iterator directly instead of the enhanced for-loop, and catch and handle the SCE:
> e.g.
> {code:java}
> Iterator<ModuleLifecycle> lifecycles = ServiceLoader.load(ModuleLifecycle.class, classLoader);
> while (lifecycles.hasNext()) {
> try {
> ModuleLifecycle lifecycle = lifecycles.next(); // This can throw SCE
> result.add(lifecycle);
> } catch (ServiceConfigurationError e) {
> // Log error
> }
> }
> {code}
> 2. Introduce a ModuleLifecycleProvider abstraction - that won't throw an SCE. The ServiceLoader spec actually recommends this:
> "The provider class is typically not the entire provider itself but rather a proxy which contains enough information to decide whether the provider is able to satisfy a particular request together with code that can create the actual provider on demand."
> In the end, this would look something like:
> {code:java}
> for (ModuleLifecycleFactory factory: ServiceLoader.load(ModuleLifecycleFactory.class, classLoader)) {
> if (factory.isEnabled()) { // returns true if create method will not throw SCE
> ModuleLifecycle lifecycle = factory.createModuleLifecycle();
> result.add(lifecycle);
> }
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years