Hi Alex,

You can find the change I did about that here:

https://github.com/apache/karaf/pull/992 
<https://github.com/apache/karaf/pull/992>

Regards
JB

> Le 12 mars 2020 à 14:02, Alex Soto <alex.s...@envieta.com> a écrit :
> 
> Thanks, JB
> 
> But it doesn’t seem to work for Karaf 4.2.8.
> I am not  familiar with the internals of Karaf code, but I spotted the 
> following in 
> org.apache.karaf.shell.impl.action.command.ManagerImpl.instantiate of  
> org.apache.karaf.shell.core-4.2.8.jar:
> 
>               Reference ref = field.getAnnotation(Reference.class);
>                 if (ref != null) {
>                     GenericType type = new 
> GenericType(field.getGenericType());
>                     Object value;
>                     if (type.getRawClass() == List.class) {
>                         Set<Object> set = new HashSet<>();
>                         
> set.addAll(registry.getServices(type.getActualTypeArgument(0).getRawClass()));
>                         if (registry != this.dependencies) {
>                             
> set.addAll(this.dependencies.getServices(type.getActualTypeArgument(0).getRawClass()));
>                         }
>                         value = new ArrayList<>(set);
>                     } else {
>                         value = registry.getService(type.getRawClass());
>                         if (value == null && registry != this.dependencies) {
>                             value = 
> this.dependencies.getService(type.getRawClass());
>                         }
>                     }
>                     if (!allowCustomServices && value == null && 
> !ref.optional()) {
>                         throw new IllegalStateException("No service matching 
> " + field.getType().getName());
>                     }
>                     field.setAccessible(true);
>                     field.set(instance, value);
>                 }
> 
> Maybe this is not the relevant piece of code, but I do not see that the 
> filter attribute is being used to look up the service.
> 
> 
> Best regards,
> Alex soto
> 
> 
> 
> 
>> On Mar 12, 2020, at 12:50 AM, Jean-Baptiste Onofre <j...@nanthrax.net 
>> <mailto:j...@nanthrax.net>> wrote:
>> 
>> Hi,
>> 
>> Yes, it’s to "select" the service you want to use.
>> 
>> I did the change because previously it wasn’t possible to select, meaning 
>> that if you had several services (with the same interface) available, it 
>> took the first one.
>> 
>> Now, you can specify the LDIF filter to select the exact service you want to 
>> inject.
>> 
>> Regards
>> JB
>> 
>>> Le 11 mars 2020 à 20:03, Alex Soto <alex.s...@envieta.com 
>>> <mailto:alex.s...@envieta.com>> a écrit :
>>> 
>>> Is the filter attribute in annotation 
>>> org.apache.karaf.shell.api.action.lifecycle.Reference used to filter the 
>>> injected service on Service attributes?
>>> 
>>> Best regards,
>>> Alex soto
>>> 
>>> 
>>> 
>>> 
>> 
> 

Reply via email to