[
https://issues.apache.org/jira/browse/FELIX-4802?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14329058#comment-14329058
]
Pierre Bourret commented on FELIX-4802:
---------------------------------------
Hi,
I think you should use the dynamic-priority binding policy for your dependency:
{code:java}
@Requires(policy=BindingPolicy.DYNAMIC_PRIORITY)
private Hello m_hellos[]; // Array => Aggregate
{code}
The iPOJO documentation is quite clear :
[http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html#managing-resilience-to-dynamism-binding-policies]
{quote}
* Dynamic policy (default): the binding are managed dynamically. At each
injection, the same provider is injected if the provider is always available.
Else a new one is chosen. For aggregate dependency, *the array order does not
change*; new providers are placed at the end of the array.
[…]
* Dynamic-priority policy: the binding is managed dynamically but the injected
provider is selected by using a ranking policy. Two injections can return two
different providers, is a new provider is 'better' than the previous one,
despite the first one is always available. For aggregate dependency, *the array
is sorted*.
{quote}
If you want to always keep your array sorted, use the dynamic priority policy.
> Aggregate Dependency with Field Injection does not respect SERVICE_RANKING
> --------------------------------------------------------------------------
>
> Key: FELIX-4802
> URL: https://issues.apache.org/jira/browse/FELIX-4802
> Project: Felix
> Issue Type: Bug
> Components: iPOJO
> Affects Versions: ipojo-runtime-1.12.1
> Environment: I found this using Apache Karaf 3.0.3
> Reporter: Andy Phillips
>
> I found an issue with the Aggregate Dependency with Field Injection where i
> have a list of "services" that i would like to maintain with a manager. The
> order of the services is important.
> I noticed that the field injection, say:
> @Component
> public class HelloConsumer {
> @Requires
> private Hello m_hellos[]; // Array => Aggregate
> public doSomething() {
> for(int I = 0; I < m_hellos.length; i++) {
> System.out.println(m_hellos[i].getMessage());
> }
> }
> }
> The initial list when the instance is "created" appears to respect the
> SERVICE_RANKING, but subequent modifications (say you install a new bundle
> with an additional "hello") does not respect the SERVICE_RANKING in the
> order. I will have to end up do my own sorting on the list prior to using
> the field.
> Is this normal? I feel that the SERVICE_RANKING should always be respected
> on the list of m_hellos[]s....
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)