-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Programmatic access to Assignability rules #498
Comments
There is already several sets of runtime assignability rules in place - at least one for beans and another for events. This is a situation I know I saw in Quarkus. And the implementations of assignability rules can then differ based on what metamodel the implementor runs on (if they use any abstraction; for example Quarkus uses Jandex). In other words, I am not sure this is unified enough to warrant putting it into specification. |
For the time being, I'd suggest grabbing resolution rules from an impl that fits your case (runtime/build time) as the feature you are implementing will be only in that space anyway. Those rules are pretty stable and don't change much so your code is highly likely to run fine even after updates. I don't think exposing those rules publicly makes a lot of sense plus I am not even sure it is doable due to aforementioned differences. The only other thing I can think of would be exposing the algorithm via |
Personally, I wouldn't expose the assignability rules directly, as that's too low-level. What might be interesting is to expose the resolution algorithm in a more fine-grained manner. For example, <T> Set<ObserverMethod<? super T>> resolveObserverMethods(T event, Annotation... qualifiers); which doesn't let you plug your own "observer method". We could add something like this: <T> boolean isMatchingObserverMethod(T event, Annotation... qualifiers, ObserverMethod<? super T> observerMethod); This method would apply the observer resolution rules to given We could expose something similar for bean resolution, too. |
For the scenario presented here, the annotation comparison is trivial, so it boils down to type assignability.
Passing around whole OM might be tricky and IMO it would be simpler to do that with type and qualifiers only. Ok, let's keep this in the CDI.next tracker and see what we can come up with. |
I used A slight variation on the sketch above would be: public interface ObserverMethodData { // bad name, anyone has a better one?
Type type();
Annotation[] qualifiers();
}
...
Set<ObserverMethodData> resolveObservers(Set<ObserverMethodData> candidates, Type eventType, Annotation... qualifiers);
... Where EDIT: or we could just use |
@Ladicek I don't think this meets the requirements of the scenario @JHahnHRO drafted.
In such case, you won't necessarily have |
I believe the original use case still requires the knowledge of event types and perhaps qualifiers, and implementing the |
Hmm, I see. As a side note, if we chose to expose these rules, we should IMO do that for beans and events but not for delegate injection points. At least not initially as I cannot imagine anyone trying to extend decorator's delegate IP somehow so it sounds like an overkill for now. |
Sure. We can either add an interface, as I mentioned above, or just accept types and annotations. Agree about the delegate injection points, that can't be practically useful. |
Some of the important algorithms outlined in pseudo-code in the spec are already available to developers of extensions, e.g. BeanManager#resolve, BeanManager#resolveDecorators and BeanManager#resolveObserverMethods. However, underlying those are other algorithms which are currently not made available to the programmer without depending on specific vendors, the type assignability rules. It is of course possible to implement the algorithms by hand when needed, the spec is clear enough to do that, but the rules are subtle enough that this is error prone and not completely trivial.
Specific use case that I have in mind: I'd like to add to the CDI container's event mechanism by also delivering events to consumers which can be registered and unregistered at runtime. In order to be consistent, I'd like the consumers to conform to the same strict type rules that observer methods have. Unfortunately, there is no quick and simple way to apply these rules except for diving into Weld's source code and stealing what I need hoping that I don't inadvertently break some subtle edge case in the process.
The text was updated successfully, but these errors were encountered: