ServiceLoader.load* take 2
paul.sandoz at oracle.com
Tue Jun 12 08:03:08 PDT 2012
A set of slides has been created  which presents a set of terms, an overview of modular services, describes the current state of affairs with service instance creation and the use of ServiceLoader.load*, then proposes an alternative solution for ServiceLoader, the first part of which is implemented by the following webrev, which changes service instance creation so that it is scoped to the configuration rather than the class loader:
Summary: in module mode any module class loader can be used with ServiceLoader to create the service instances for a service interface. Previously the class loader of the service consumer module, that consumes the service interface, was required to be used.
- Modify the configuration so that service information is stored directly with the configuration rather than with each context (that is stored with the configuration). Currently service provider classes are looked up by iterating through all the contexts. This is not very efficient. The configuration is the place where to optimize.
This requires some refactoring of org.openjdk.jigsaw.Configuration because for instances of Configuration<PathContext> (the configuration produced when compiling) such state related to services is not relevant. This is also a potential opportunity to improve the immutability of Configuration using a builder pattern for construction.
- Modify the resolver so that the permits clause does not affect resolution of a service provider module (and it's dependencies). This area is tricky. Rather than choices of service provider module optional dependencies being pushed on to the choice stack of each service consumer module this potentially could be done once per service interface (although will likely change what solutions are produced), but might be very tricky to implement given that service provider modules may also be service consumer modules. Good diagnostics are required to help track down why a service provider module is not being resolved.
More information about the jigsaw-dev