[cdi-dev] Consistency across specs with the use of @Priority

Martin Kouba mkouba at redhat.com
Mon Oct 23 03:25:36 EDT 2017


Just to sum it up. In CDI we use pririority (either @Priority or 
Prioritized) to:
- select an alternative globally and resolve ambiguous dependencies
- enable interceptor globally
- enable decorator
- order observers
- order CDIProviders

For alternatives the _highest_ priority value wins.

Interceptors and decorators with the _smaller_ priority values are 
called first which means that an interceptor/decorator with highest 
priority value is the "closest" to a bean business method invocation.

Observers with _smaller_ priority values are called first. BTW there was 
a vote about observer ordering:
http://lists.jboss.org/pipermail/cdi-dev/2016-December/009410.html

CDIProvider with _highest_ priority is used.

Personally, I think it's more natural to process components with higher 
priority first (note that priority != order). But when it comes to 
interceptor chains things get more complicated.

Martin


Dne 23.10.2017 v 07:10 Romain Manni-Bucau napsal(a):
>  From what I recall it is not the same for interceptors and decorators 
> too. More about the chain vision and what is the "0" from my understanding.
> 
> Le 23 oct. 2017 03:55, "John Ament" <john.ament at spartasystems.com 
> <mailto:john.ament at spartasystems.com>> a écrit :
> 
>     I found this interesting to say the least. In CDI, we use highest
>     priority where the value of the @Priority annotation is compared the
>     higher numeric value is considered higher priority.  We followed
>     suite so far in MicroProfile specs. I'm not looking to throw dirt,
>     but wanted to get a general opinion from others on this.  The JAX-RS
>     treats the lower numeric value as more important (in mathematical
>     terms, it's being treated as the denominator).
> 
> 
>      > If two or more providers are candidates for a certain task, the
>     one with the highest priority is chosen: the highest priority is
>     defined to be the one with the lowest value in this case. That is,
>     @Priority(1) is higher than @Priority(10).
> 
>     So I'm wondering, why did CDI use the approach that CDI is using?
> 
> 
>     John
> 
> 
>     ------------------------------------------------------------------------
>     NOTICE: This e-mail message and any attachments may contain
>     confidential, proprietary, and/or privileged information which
>     should be treated accordingly. If you are not the intended
>     recipient, please notify the sender immediately by return e-mail,
>     delete this message, and destroy all physical and electronic copies.
>     Thank you.
> 
>     _______________________________________________
>     cdi-dev mailing list
>     cdi-dev at lists.jboss.org <mailto:cdi-dev at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/cdi-dev
>     <https://lists.jboss.org/mailman/listinfo/cdi-dev>
> 
>     Note that for all code provided on this list, the provider licenses
>     the code under the Apache License, Version 2
>     (http://www.apache.org/licenses/LICENSE-2.0.html
>     <http://www.apache.org/licenses/LICENSE-2.0.html>). For all other
>     ideas provided on this list, the provider waives all patent and
>     other intellectual property rights inherent in such information.
> 
> 
> 
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
> 
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.
> 

-- 
Martin Kouba
Senior Software Engineer
Red Hat, Czech Republic


More information about the cdi-dev mailing list