[ 
https://issues.apache.org/jira/browse/FELIX-5337?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15657899#comment-15657899
 ] 

Pierre De Rop commented on FELIX-5337:
--------------------------------------

I reverted the patch from revision 1759575 and uncommitted it (in revision 
1769329).

Indeed, it breaks the contract of the original 
ServiceDependency.SetService(Class<?> serviceName, String serviceFilter) in the 
DM api. Indeed, Dobias reported in FELIX-5403 that the following code which 
worked well before is not working anymore with the patch from rev 1759575:

{code}
manager.createServiceDependency()
        .setService(StoreService.class, "(!(objectClass=" + 
ConsequenceStoreService.class.getName() + "))")
        .setCallbacks("addStoreService", null, "removeStoreService", 
"swapStoreService");
{code}

Indeed, with the wrong patch, the filter is not extended anymore with the type 
of the serviceName (StoreService).

Now, I will try to find a solution for the initial problem of this issue, which 
is: if you want to catch all services using the following code:

{code}
        @ServiceDependency(filter="(objectClass=*)", required = false) 
        void addService(Object service) {
                System.out.println("Got service " + service);
        }
{code}

then the problem is that the type of the "addService" parameter (Object) is 
used and the runtime then uses the following DM api method with the service 
type (Object), and the filter like this:

{code}
createServiceDependency().setService(Object.class, 
"(objectClass=*)").setRequired(false)
{code}

So, the setService method then uses the following filter, which is not what we 
want since we need to catch all services:

{code}
(&(objectClass=java.lang.Object)(objectClass=*))
{code}

I have to think more about this issue.

currently, the only work around is to use a ServiceReference in the 
addServiceParameter: in this case, since we can't infer the service type, we 
then end up using only the following DM api method, which works:

{code}
createServiceDependency().setService("(objectClass=*)").setRequired(false)
{code}

> Filter-based dependencies working differently for annotations
> -------------------------------------------------------------
>
>                 Key: FELIX-5337
>                 URL: https://issues.apache.org/jira/browse/FELIX-5337
>             Project: Felix
>          Issue Type: Bug
>    Affects Versions: dependencymanager-4.3.0
>            Reporter: J.W. Janssen
>            Assignee: Pierre De Rop
>
> I've got a "catch all" service dependency that simply wants to see *all* 
> services being registered. In the activator based implementation I simply 
> express my dependency as 
> {{createServiceDependency().setService("(objectClass=*)").setRequired(false).setCallbacks("addService",
>  "removeService")}} and I get all services I'm interested in (I mean: each 
> and every registered service).
> However, if I rewrite my code to use annotations using 
> {{@ServiceDependency(filter="(objectClass=*)", required = false, removed = 
> ...)}}, I suddenly do not see all services I expect: only services that seem 
> to be compatible with the class-space of the bundle my code lives in.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to