Open glassfishrobot opened 9 years ago
@glassfishrobot Commented Reported by @saden1
@glassfishrobot Commented @jwells131313 said: I guess I don't understand this request. Most features (such as topic distribution, or new contexts) are already just HK2 services, and so are able to be added dynamically like anything else. Most of those "enableTopicDistribution" type things are just there to add the default HK2 versions of those services.
So... seems like hk2 already does this? Am I missing something? The only other thing that you mention here which is about a way to only register something if not already registered is already covered in #273 I think
@glassfishrobot Commented @saden1 said: Sorry I wasn't clear, I probably should have formulated my thoughts better before creating the issue.
What I am really getting at is a formalized and documented move towards modularity and extensibility by HK2. While everything is just a service that can be added dynamically features are intrinsically different from just a collection of services in that they facilitate extension of HK2. Today, if you wanted to add a new feature to HK2 it would requires the addition of yet another ServiceLocatorUtilities.enableAwesomeFeature(locator) method. In addition these features are inseparable from the other features and even though one doesn't have to enable them they are there nonetheless. As HK2 grows this way of doing things is probably not scalable. Then there are HK2 features like AOP which are features that don't require enablement but are there.
Right now HK2 has all the fundamental building blocks necessary to get the ball rolling on implementing the feature concept.
Internally HK2 will need to take a few steps but after that adding and "enabling" a feature will be a matter of adding a jar file to your classpath or implementing a feature and making it available for population via a Binder or classpath discriptors:
p.s Out of curiosity why isn't there a bind method in the ServiceLocator contract/impl?
@glassfishrobot Commented @jwells131313 said: I'll answer that last question first: There is no bind method in ServiceLocator because ServiceLocator is supposed to be about finding services and/or descriptors. In fact, the ONLY true way to add and remove descriptors from a Locator is with the DynamicConfiguration.commit method (DynamicConfiguration objects coming from the DynamicConfigurationService service). ALL other ways of adding/removing descriptors to a ServiceLocator are completely built on the DynamicConfiguration.commit method. This includes both types of EDSL binders, as well as all the ServiceLocatorUtilities methods such as "addClasses" and the like, and even the populate methods that read the service-locator files from jars eventually just boil down to the DynamicConfiguration.commit method.
That being said, I like your idea of a grouping of services that can be considered a feature. Then features can depend on other features etc. We have the start of that (such as the EDSL binder methods, which can group services). However, I do think some more infrastructure is needed to truly support them, and things like dependencies between them, and even things like being able to remove them cogently from a running ServiceLocator. Those last few things we certainly do not have right now.
@glassfishrobot Commented This issue was imported from java.net JIRA HK2-239
Currently enabling or adding new features to HK2 is not flexible or dynamic. HK2 should emulate Jersey which seems to have the right idea with their Feature and AutoDiscoverable functionality.
Ideally I would love to be able to:
Register existing feature``` //no more ServiceLocatorUtilities.enableTopicDistribution(locator); locator.register(TopicDistribution.class);
Register a custom feature``` //enable feature class locator.register(SomeFeature.class); //enable an instance of a feature class locator.register(new SomeFeature());
Dynamically register features via ServiceLoader spi``` //discovered and called by service locator during locator creation process public class MyFeatures implements ServiceLocatorAutoDiscovery { public boolean configure(ServiceLocatorContext context) { //context allows for the ability to register a feature, get the //underlying service locator, add/build new descriptor/services, //register binders, etc. //i.e. if(context.isRegistered(SomeFeature.class) { context.register(SomeFeature.class); } } }