You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Felix Meschberger <fm...@adobe.com> on 2012/06/29 13:54:47 UTC

ServiceUtil ordering (was: customizing resourceType resolution?)

Hi,

Am 28.06.2012 um 23:56 schrieb sam ”:

> It looks like ResourceDecorators are ordered by service.ranking property
> in ascending order.
> 
> @Properties({
>    @Property(name = Constants.SERVICE_RANKING, intValue = 10)
> })
> public class  Apple implements ResourceDecorator {
> ...
> }
> 
> @Properties({
>    @Property(name = Constants.SERVICE_RANKING, intValue = 20)
> })
> public class  Orange implements ResourceDecorator {
> ...
> }
> 
> 
> Given above,   Apple is executed first, then Orange, according to:
> http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java
> 
> 
> This is sort of unintuitive to me because there is this:
> http://www.osgi.org/javadoc/r2/org/osgi/framework/Constants.html#SERVICE_RANKING
> The default ranking is 0. A service with a ranking of Integer.MAX_VALUE is
> very likely to be returned as the default service, whereas a service with a
> ranking of Integer.MIN_VALUE is very unlikely to be returned.

Don't know about how the resource decoarator services are sorted, but if ServiceUtil orders differently than implemented by ServiceReference instances, this would IMHO be a bug.

Can someone confirm this ?

Regards
Felix

Re: ServiceUtil ordering (was: customizing resourceType resolution?)

Posted by Felix Meschberger <fm...@adobe.com>.
Thanks. Just wanted to make sure ;-)

Regards
Felix

Am 01.07.2012 um 17:00 schrieb Carsten Ziegeler:

> In general, services with higher ranking have preference over services
> with lower values. That's why we call services with lower ranking in
> the decorator case first. Decorators with a higher ranking come last
> and therefore have the final saying.
> 
> So I think everything is fine here :)
> 
> Regards
> Carsten
> 
> 2012/6/29 Felix Meschberger <fm...@adobe.com>:
>> Hi,
>> 
>> Am 28.06.2012 um 23:56 schrieb sam ”:
>> 
>>> It looks like ResourceDecorators are ordered by service.ranking property
>>> in ascending order.
>>> 
>>> @Properties({
>>>   @Property(name = Constants.SERVICE_RANKING, intValue = 10)
>>> })
>>> public class  Apple implements ResourceDecorator {
>>> ...
>>> }
>>> 
>>> @Properties({
>>>   @Property(name = Constants.SERVICE_RANKING, intValue = 20)
>>> })
>>> public class  Orange implements ResourceDecorator {
>>> ...
>>> }
>>> 
>>> 
>>> Given above,   Apple is executed first, then Orange, according to:
>>> http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java
>>> 
>>> 
>>> This is sort of unintuitive to me because there is this:
>>> http://www.osgi.org/javadoc/r2/org/osgi/framework/Constants.html#SERVICE_RANKING
>>> The default ranking is 0. A service with a ranking of Integer.MAX_VALUE is
>>> very likely to be returned as the default service, whereas a service with a
>>> ranking of Integer.MIN_VALUE is very unlikely to be returned.
>> 
>> Don't know about how the resource decoarator services are sorted, but if ServiceUtil orders differently than implemented by ServiceReference instances, this would IMHO be a bug.
>> 
>> Can someone confirm this ?
>> 
>> Regards
>> Felix
> 
> 
> 
> -- 
> Carsten Ziegeler
> cziegeler@apache.org


Re: ServiceUtil ordering (was: customizing resourceType resolution?)

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Sun, Jul 1, 2012 at 5:00 PM, Carsten Ziegeler <cz...@apache.org> wrote:
> In general, services with higher ranking have preference over services
> with lower values. That's why we call services with lower ranking in
> the decorator case first. Decorators with a higher ranking come last
> and therefore have the final saying.
>
> So I think everything is fine here :)

I agree, and to be complete here's how the Spec defines comparing two
services based on their ServiceReference:
http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/ServiceReference.html#compareTo(java.lang.Object)

-Bertrand

Re: ServiceUtil ordering (was: customizing resourceType resolution?)

Posted by Carsten Ziegeler <cz...@apache.org>.
In general, services with higher ranking have preference over services
with lower values. That's why we call services with lower ranking in
the decorator case first. Decorators with a higher ranking come last
and therefore have the final saying.

So I think everything is fine here :)

Regards
Carsten

2012/6/29 Felix Meschberger <fm...@adobe.com>:
> Hi,
>
> Am 28.06.2012 um 23:56 schrieb sam ”:
>
>> It looks like ResourceDecorators are ordered by service.ranking property
>> in ascending order.
>>
>> @Properties({
>>    @Property(name = Constants.SERVICE_RANKING, intValue = 10)
>> })
>> public class  Apple implements ResourceDecorator {
>> ...
>> }
>>
>> @Properties({
>>    @Property(name = Constants.SERVICE_RANKING, intValue = 20)
>> })
>> public class  Orange implements ResourceDecorator {
>> ...
>> }
>>
>>
>> Given above,   Apple is executed first, then Orange, according to:
>> http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/osgi/src/main/java/org/apache/sling/commons/osgi/ServiceUtil.java
>>
>>
>> This is sort of unintuitive to me because there is this:
>> http://www.osgi.org/javadoc/r2/org/osgi/framework/Constants.html#SERVICE_RANKING
>> The default ranking is 0. A service with a ranking of Integer.MAX_VALUE is
>> very likely to be returned as the default service, whereas a service with a
>> ranking of Integer.MIN_VALUE is very unlikely to be returned.
>
> Don't know about how the resource decoarator services are sorted, but if ServiceUtil orders differently than implemented by ServiceReference instances, this would IMHO be a bug.
>
> Can someone confirm this ?
>
> Regards
> Felix



-- 
Carsten Ziegeler
cziegeler@apache.org