You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Matthias Leinweber <Ma...@IDA-Analytics.de> on 2019/05/15 13:35:02 UTC

Service Sisibility

Hello Karaf Experts,


i am trying to isolate services from each other.


For Example you have a component:


@Component(
    configurationPid = "MyInterfacA.factory",
    configurationPolicy = ConfigurationPolicy.REQUIRE,
public Class MyInterfaceAImpl implements MyInterfacA{


@Reference

MyInterfaceB service;


 ...}


During runtime I create multiple services from type MyInterfaceB and multiple componentes of MyInterfaceAImpl with configadmin.

Depending on the configuration of MyInterfaceAImpl I want to filter which MyInterfaceB implementation is injected.

I thought about FindHook but there I dont see a way how to get the information which service from the bundle is requesting the reference.


Is there any chance to do this, or do I have to go for an alternative design. Or a better way to isolate services from another?



Best regards,

Matthias

Re: Service Sisibility

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Matthias,

Can't you use filter ?

Each service implementing MyInterfaceB can use a service property that
you filter on @Reference.

Regards
JB

On 15/05/2019 15:35, Matthias Leinweber wrote:
> Hello Karaf Experts,
> 
> 
> i am trying to isolate services from each other. 
> 
> 
> For Exampleyou have a component:
> 
> 
> @Component(
>     configurationPid = "MyInterfacA.factory",
>     configurationPolicy = ConfigurationPolicy.REQUIRE,
> public Class MyInterfaceAImpl implements MyInterfacA{
> 
> @Reference
> 
> MyInterfaceB service;
> 
> 
>  ...}
> 
> 
> During runtime I create multiple services from type MyInterfaceB and
> multiple componentes of MyInterfaceAImpl with configadmin.
> 
> Depending on the configuration of MyInterfaceAImpl I want to filter
> which MyInterfaceB implementation is injected.
> 
> I thought about FindHook but there I dont see a way how to get the
> information which service from the bundle is requesting the reference.
> 
> 
> Is there any chance to do this, or do I have to go for an alternative
> design. Or a better way to isolate services from another?
> 
> 
> 
> Best regards,
> 
> Matthias
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: AW: Service Sisibility

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Yeah, I should have pointed on Decanter example, like this one for instance:

https://github.com/apache/karaf-decanter/blob/master/appender/log/src/main/cfg/org.apache.karaf.decanter.appender.log.cfg#L25

Thanks Tim ;)

Regards
JB

On 15/05/2019 18:02, Tim Ward wrote:
> The “secret sauce” is knowing that you can set the target filter using configuration, not just statically in the @Reference annotation. Static filters can be useful, but configurable filters are indistinguishable from magic 😊
> 
> Tim
> 
> Sent from my iPhone
> 
>> On 15 May 2019, at 15:21, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
>>
>> Hi,
>>
>> Yes, it's exactly what I meant by filter. It's what we are using in
>> Karaf Decanter.
>>
>> Cool it fits your need ;)
>>
>> Regards
>> JB
>>
>>> On 15/05/2019 16:05, Matthias Leinweber wrote:
>>> Thank you Tim, 
>>>
>>>
>>> Ok thats really amazing! That was exactly what i was looking for. 
>>>
>>> I can change the name target name with @Referance(name="foo") so a bit
>>> more transparency.
>>>
>>>
>>> Each day I am discovering something like this i like OSGI and Karaf a
>>> bit more. 
>>>
>>>
>>> br,
>>>
>>> Matthias
>>>
>>> ------------------------------------------------------------------------
>>> *Von:* Tim Ward <ti...@paremus.com>
>>> *Gesendet:* Mittwoch, 15. Mai 2019 15:45:20
>>> *An:* user@karaf.apache.org
>>> *Betreff:* Re: Service Sisibility
>>>  
>>> Declarative Services is amazing, so this is trivially easy to do. In
>>> this case you should add the configuration property
>>>
>>>    *service.target*
>>>
>>>
>>> to your configuration dictionary with the value being an LDAP filter
>>> selecting the service you want to inject. 
>>>
>>> Note that “service” is the name of your reference (it defaults to the
>>> field name) and that if your reference has a different name (e.g. if you
>>> change the name of the field) then the name of the property will change too.
>>>
>>> For example:
>>>
>>>    service.target=(foo=bar)
>>>
>>>
>>> Inject me with a MyInterfaceB which has the service property foo equal
>>> to bar.
>>>
>>> All the best,
>>>
>>> Tim
>>>
>>>> On 15 May 2019, at 14:35, Matthias Leinweber
>>>> <Matthias.Leinweber@IDA-Analytics.de
>>>> <ma...@IDA-Analytics.de>> wrote:
>>>>
>>>> Hello Karaf Experts,
>>>>
>>>> i am trying to isolate services from each other. 
>>>>
>>>> For Example you have a component:
>>>>
>>>> @Component(
>>>>     configurationPid = "MyInterfacA.factory",
>>>>     configurationPolicy = ConfigurationPolicy.REQUIRE,
>>>> public Class MyInterfaceAImpl implements MyInterfacA{
>>>>
>>>> @Reference
>>>> MyInterfaceB service;
>>>>
>>>>  ...}
>>>>
>>>> During runtime I create multiple services from type MyInterfaceB and
>>>> multiple componentes of MyInterfaceAImpl with configadmin.
>>>> Depending on the configuration of MyInterfaceAImpl I want to filter
>>>> which MyInterfaceB implementation is injected.
>>>>
>>>> I thought about FindHook but there I dont see a way how to get the
>>>> information which service from the bundle is requesting the reference.
>>>>
>>>>
>>>> Is there any chance to do this, or do I have to go for an alternative
>>>> design. Or a better way to isolate services from another?
>>>>
>>>>
>>>> Best regards,
>>>> Matthias
>>>
>>
>> -- 
>> Jean-Baptiste Onofré
>> jbonofre@apache.org
>> http://blog.nanthrax.net
>> Talend - http://www.talend.com

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: AW: Service Sisibility

Posted by Tim Ward <ti...@paremus.com>.
The “secret sauce” is knowing that you can set the target filter using configuration, not just statically in the @Reference annotation. Static filters can be useful, but configurable filters are indistinguishable from magic 😊

Tim

Sent from my iPhone

> On 15 May 2019, at 15:21, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:
> 
> Hi,
> 
> Yes, it's exactly what I meant by filter. It's what we are using in
> Karaf Decanter.
> 
> Cool it fits your need ;)
> 
> Regards
> JB
> 
>> On 15/05/2019 16:05, Matthias Leinweber wrote:
>> Thank you Tim, 
>> 
>> 
>> Ok thats really amazing! That was exactly what i was looking for. 
>> 
>> I can change the name target name with @Referance(name="foo") so a bit
>> more transparency.
>> 
>> 
>> Each day I am discovering something like this i like OSGI and Karaf a
>> bit more. 
>> 
>> 
>> br,
>> 
>> Matthias
>> 
>> ------------------------------------------------------------------------
>> *Von:* Tim Ward <ti...@paremus.com>
>> *Gesendet:* Mittwoch, 15. Mai 2019 15:45:20
>> *An:* user@karaf.apache.org
>> *Betreff:* Re: Service Sisibility
>>  
>> Declarative Services is amazing, so this is trivially easy to do. In
>> this case you should add the configuration property
>> 
>>    *service.target*
>> 
>> 
>> to your configuration dictionary with the value being an LDAP filter
>> selecting the service you want to inject. 
>> 
>> Note that “service” is the name of your reference (it defaults to the
>> field name) and that if your reference has a different name (e.g. if you
>> change the name of the field) then the name of the property will change too.
>> 
>> For example:
>> 
>>    service.target=(foo=bar)
>> 
>> 
>> Inject me with a MyInterfaceB which has the service property foo equal
>> to bar.
>> 
>> All the best,
>> 
>> Tim
>> 
>>> On 15 May 2019, at 14:35, Matthias Leinweber
>>> <Matthias.Leinweber@IDA-Analytics.de
>>> <ma...@IDA-Analytics.de>> wrote:
>>> 
>>> Hello Karaf Experts,
>>> 
>>> i am trying to isolate services from each other. 
>>> 
>>> For Example you have a component:
>>> 
>>> @Component(
>>>     configurationPid = "MyInterfacA.factory",
>>>     configurationPolicy = ConfigurationPolicy.REQUIRE,
>>> public Class MyInterfaceAImpl implements MyInterfacA{
>>> 
>>> @Reference
>>> MyInterfaceB service;
>>> 
>>>  ...}
>>> 
>>> During runtime I create multiple services from type MyInterfaceB and
>>> multiple componentes of MyInterfaceAImpl with configadmin.
>>> Depending on the configuration of MyInterfaceAImpl I want to filter
>>> which MyInterfaceB implementation is injected.
>>> 
>>> I thought about FindHook but there I dont see a way how to get the
>>> information which service from the bundle is requesting the reference.
>>> 
>>> 
>>> Is there any chance to do this, or do I have to go for an alternative
>>> design. Or a better way to isolate services from another?
>>> 
>>> 
>>> Best regards,
>>> Matthias
>> 
> 
> -- 
> Jean-Baptiste Onofré
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com

Re: AW: Service Sisibility

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

Yes, it's exactly what I meant by filter. It's what we are using in
Karaf Decanter.

Cool it fits your need ;)

Regards
JB

On 15/05/2019 16:05, Matthias Leinweber wrote:
> Thank you Tim, 
> 
> 
> Ok thats really amazing! That was exactly what i was looking for. 
> 
> I can change the name target name with @Referance(name="foo") so a bit
> more transparency.
> 
> 
> Each day I am discovering something like this i like OSGI and Karaf a
> bit more. 
> 
> 
> br,
> 
> Matthias
> 
> ------------------------------------------------------------------------
> *Von:* Tim Ward <ti...@paremus.com>
> *Gesendet:* Mittwoch, 15. Mai 2019 15:45:20
> *An:* user@karaf.apache.org
> *Betreff:* Re: Service Sisibility
>  
> Declarative Services is amazing, so this is trivially easy to do. In
> this case you should add the configuration property
> 
>     *service.target*
> 
> 
> to your configuration dictionary with the value being an LDAP filter
> selecting the service you want to inject. 
> 
> Note that “service” is the name of your reference (it defaults to the
> field name) and that if your reference has a different name (e.g. if you
> change the name of the field) then the name of the property will change too.
> 
> For example:
> 
>     service.target=(foo=bar)
> 
> 
> Inject me with a MyInterfaceB which has the service property foo equal
> to bar.
> 
> All the best,
> 
> Tim
> 
>> On 15 May 2019, at 14:35, Matthias Leinweber
>> <Matthias.Leinweber@IDA-Analytics.de
>> <ma...@IDA-Analytics.de>> wrote:
>>
>> Hello Karaf Experts,
>>
>> i am trying to isolate services from each other. 
>>
>> For Example you have a component:
>>
>> @Component(
>>     configurationPid = "MyInterfacA.factory",
>>     configurationPolicy = ConfigurationPolicy.REQUIRE,
>> public Class MyInterfaceAImpl implements MyInterfacA{
>>
>> @Reference
>> MyInterfaceB service;
>>
>>  ...}
>>
>> During runtime I create multiple services from type MyInterfaceB and
>> multiple componentes of MyInterfaceAImpl with configadmin.
>> Depending on the configuration of MyInterfaceAImpl I want to filter
>> which MyInterfaceB implementation is injected.
>>
>> I thought about FindHook but there I dont see a way how to get the
>> information which service from the bundle is requesting the reference.
>>
>>
>> Is there any chance to do this, or do I have to go for an alternative
>> design. Or a better way to isolate services from another?
>>
>>
>> Best regards,
>> Matthias
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

AW: Service Sisibility

Posted by Matthias Leinweber <Ma...@IDA-Analytics.de>.
Thank you Tim,


Ok thats really amazing! That was exactly what i was looking for.

I can change the name target name with @Referance(name="foo") so a bit more transparency.


Each day I am discovering something like this i like OSGI and Karaf a bit more.


br,

Matthias

________________________________
Von: Tim Ward <ti...@paremus.com>
Gesendet: Mittwoch, 15. Mai 2019 15:45:20
An: user@karaf.apache.org
Betreff: Re: Service Sisibility

Declarative Services is amazing, so this is trivially easy to do. In this case you should add the configuration property

service.target

to your configuration dictionary with the value being an LDAP filter selecting the service you want to inject.

Note that “service” is the name of your reference (it defaults to the field name) and that if your reference has a different name (e.g. if you change the name of the field) then the name of the property will change too.

For example:

service.target=(foo=bar)

Inject me with a MyInterfaceB which has the service property foo equal to bar.

All the best,

Tim

On 15 May 2019, at 14:35, Matthias Leinweber <Ma...@IDA-Analytics.de>> wrote:

Hello Karaf Experts,

i am trying to isolate services from each other.

For Example you have a component:


@Component(
    configurationPid = "MyInterfacA.factory",
    configurationPolicy = ConfigurationPolicy.REQUIRE,
public Class MyInterfaceAImpl implements MyInterfacA{


@Reference
MyInterfaceB service;

 ...}

During runtime I create multiple services from type MyInterfaceB and multiple componentes of MyInterfaceAImpl with configadmin.
Depending on the configuration of MyInterfaceAImpl I want to filter which MyInterfaceB implementation is injected.

I thought about FindHook but there I dont see a way how to get the information which service from the bundle is requesting the reference.

Is there any chance to do this, or do I have to go for an alternative design. Or a better way to isolate services from another?


Best regards,
Matthias


Re: Service Sisibility

Posted by Raymond Auge <ra...@liferay.com>.
On Wed, May 15, 2019 at 4:45 PM Markus Rathgeb <ma...@gmail.com> wrote:

> Thanks a lot!
>
> Am Mi., 15. Mai 2019 um 21:14 Uhr schrieb David Jencks
> <da...@gmail.com>:
> >
> > for instance, from R7 cmpn…
> >
> > 112.3.10 Selecting Target Services
> >
> > …
> >         • The filter is manifested as a component property called the
> target property. The target property can also be set by property and
> properties elements, see Property and Properties Elements on page 339. The
> deployer can also set the target property by establishing a configuration
> for the component which sets the value of the target property. This allows
> the deployer to override the target property in the component description.
> See Target Property on page 357 for more information.
>

Let me further bolster that quote with a link to the official web version
[1] for your convenient perusal.

- Ray

[1]
https://osgi.org/specification/osgi.cmpn/7.0.0/service.component.html#service.component-selecting.target.services


> >
> > also 112.6.2.1
> >
> >  Hope this helps
> >
> > David Jencks
> >
> > > On May 15, 2019, at 10:28 AM, Markus Rathgeb <ma...@gmail.com>
> wrote:
> > >
> > > Hi Tim,
> > >
> > > can you point me to the part of the spec that states that service
> configuration properties can be used to set such fields (e.g. target
> filter)?
> > > I just know that it works ;)
> > >
> > > Best regards,
> > > Markus
> > >
> > > Tim Ward <ti...@paremus.com> schrieb am Mi., 15. Mai 2019, 15:45:
> > > Declarative Services is amazing, so this is trivially easy to do. In
> this case you should add the configuration property
> > >
> > > service.target
> > >
> > > to your configuration dictionary with the value being an LDAP filter
> selecting the service you want to inject.
> > >
> > > Note that “service” is the name of your reference (it defaults to the
> field name) and that if your reference has a different name (e.g. if you
> change the name of the field) then the name of the property will change too.
> > >
> > > For example:
> > >
> > > service.target=(foo=bar)
> > >
> > > Inject me with a MyInterfaceB which has the service property foo equal
> to bar.
> > >
> > > All the best,
> > >
> > > Tim
> > >
> > >> On 15 May 2019, at 14:35, Matthias Leinweber
> <Ma...@IDA-Analytics.de> wrote:
> > >>
> > >> Hello Karaf Experts,
> > >>
> > >> i am trying to isolate services from each other.
> > >>
> > >> For Example you have a component:
> > >>
> > >> @Component(
> > >>     configurationPid = "MyInterfacA.factory",
> > >>     configurationPolicy = ConfigurationPolicy.REQUIRE,
> > >> public Class MyInterfaceAImpl implements MyInterfacA{
> > >>
> > >> @Reference
> > >> MyInterfaceB service;
> > >>
> > >>  ...}
> > >>
> > >> During runtime I create multiple services from type MyInterfaceB and
> multiple componentes of MyInterfaceAImpl with configadmin.
> > >> Depending on the configuration of MyInterfaceAImpl I want to filter
> which MyInterfaceB implementation is injected.
> > >>
> > >> I thought about FindHook but there I dont see a way how to get the
> information which service from the bundle is requesting the reference.
> > >>
> > >> Is there any chance to do this, or do I have to go for an alternative
> design. Or a better way to isolate services from another?
> > >>
> > >>
> > >> Best regards,
> > >> Matthias
> > >
> >
>


-- 
*Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile>
 (@rotty3000)
Senior Software Architect *Liferay, Inc.* <http://www.liferay.com>
 (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> (@OSGiAlliance)

Re: Service Sisibility

Posted by Markus Rathgeb <ma...@gmail.com>.
Thanks a lot!

Am Mi., 15. Mai 2019 um 21:14 Uhr schrieb David Jencks
<da...@gmail.com>:
>
> for instance, from R7 cmpn…
>
> 112.3.10 Selecting Target Services
>
> …
>         • The filter is manifested as a component property called the target property. The target property can also be set by property and properties elements, see Property and Properties Elements on page 339. The deployer can also set the target property by establishing a configuration for the component which sets the value of the target property. This allows the deployer to override the target property in the component description. See Target Property on page 357 for more information.
>
> also 112.6.2.1
>
>  Hope this helps
>
> David Jencks
>
> > On May 15, 2019, at 10:28 AM, Markus Rathgeb <ma...@gmail.com> wrote:
> >
> > Hi Tim,
> >
> > can you point me to the part of the spec that states that service configuration properties can be used to set such fields (e.g. target filter)?
> > I just know that it works ;)
> >
> > Best regards,
> > Markus
> >
> > Tim Ward <ti...@paremus.com> schrieb am Mi., 15. Mai 2019, 15:45:
> > Declarative Services is amazing, so this is trivially easy to do. In this case you should add the configuration property
> >
> > service.target
> >
> > to your configuration dictionary with the value being an LDAP filter selecting the service you want to inject.
> >
> > Note that “service” is the name of your reference (it defaults to the field name) and that if your reference has a different name (e.g. if you change the name of the field) then the name of the property will change too.
> >
> > For example:
> >
> > service.target=(foo=bar)
> >
> > Inject me with a MyInterfaceB which has the service property foo equal to bar.
> >
> > All the best,
> >
> > Tim
> >
> >> On 15 May 2019, at 14:35, Matthias Leinweber <Ma...@IDA-Analytics.de> wrote:
> >>
> >> Hello Karaf Experts,
> >>
> >> i am trying to isolate services from each other.
> >>
> >> For Example you have a component:
> >>
> >> @Component(
> >>     configurationPid = "MyInterfacA.factory",
> >>     configurationPolicy = ConfigurationPolicy.REQUIRE,
> >> public Class MyInterfaceAImpl implements MyInterfacA{
> >>
> >> @Reference
> >> MyInterfaceB service;
> >>
> >>  ...}
> >>
> >> During runtime I create multiple services from type MyInterfaceB and multiple componentes of MyInterfaceAImpl with configadmin.
> >> Depending on the configuration of MyInterfaceAImpl I want to filter which MyInterfaceB implementation is injected.
> >>
> >> I thought about FindHook but there I dont see a way how to get the information which service from the bundle is requesting the reference.
> >>
> >> Is there any chance to do this, or do I have to go for an alternative design. Or a better way to isolate services from another?
> >>
> >>
> >> Best regards,
> >> Matthias
> >
>

Re: Service Sisibility

Posted by David Jencks <da...@gmail.com>.
for instance, from R7 cmpn…

112.3.10 Selecting Target Services 

…
	• The filter is manifested as a component property called the target property. The target property can also be set by property and properties elements, see Property and Properties Elements on page 339. The deployer can also set the target property by establishing a configuration for the component which sets the value of the target property. This allows the deployer to override the target property in the component description. See Target Property on page 357 for more information. 

also 112.6.2.1  

 Hope this helps

David Jencks

> On May 15, 2019, at 10:28 AM, Markus Rathgeb <ma...@gmail.com> wrote:
> 
> Hi Tim,
> 
> can you point me to the part of the spec that states that service configuration properties can be used to set such fields (e.g. target filter)?
> I just know that it works ;)
> 
> Best regards,
> Markus
> 
> Tim Ward <ti...@paremus.com> schrieb am Mi., 15. Mai 2019, 15:45:
> Declarative Services is amazing, so this is trivially easy to do. In this case you should add the configuration property
> 
> service.target
> 
> to your configuration dictionary with the value being an LDAP filter selecting the service you want to inject. 
> 
> Note that “service” is the name of your reference (it defaults to the field name) and that if your reference has a different name (e.g. if you change the name of the field) then the name of the property will change too.
> 
> For example:
> 
> service.target=(foo=bar)
> 
> Inject me with a MyInterfaceB which has the service property foo equal to bar.
> 
> All the best,
> 
> Tim
> 
>> On 15 May 2019, at 14:35, Matthias Leinweber <Ma...@IDA-Analytics.de> wrote:
>> 
>> Hello Karaf Experts,
>> 
>> i am trying to isolate services from each other. 
>> 
>> For Example you have a component:
>> 
>> @Component(
>>     configurationPid = "MyInterfacA.factory",
>>     configurationPolicy = ConfigurationPolicy.REQUIRE,
>> public Class MyInterfaceAImpl implements MyInterfacA{
>> 
>> @Reference
>> MyInterfaceB service;
>> 
>>  ...}
>> 
>> During runtime I create multiple services from type MyInterfaceB and multiple componentes of MyInterfaceAImpl with configadmin.
>> Depending on the configuration of MyInterfaceAImpl I want to filter which MyInterfaceB implementation is injected.
>> 
>> I thought about FindHook but there I dont see a way how to get the information which service from the bundle is requesting the reference.
>> 
>> Is there any chance to do this, or do I have to go for an alternative design. Or a better way to isolate services from another?
>> 
>> 
>> Best regards,
>> Matthias
> 


Re: Service Sisibility

Posted by Markus Rathgeb <ma...@gmail.com>.
Hi Tim,

can you point me to the part of the spec that states that service
configuration properties can be used to set such fields (e.g. target
filter)?
I just know that it works ;)

Best regards,
Markus

Tim Ward <ti...@paremus.com> schrieb am Mi., 15. Mai 2019, 15:45:

> Declarative Services is amazing, so this is trivially easy to do. In this
> case you should add the configuration property
>
> *service.target*
>
>
> to your configuration dictionary with the value being an LDAP filter
> selecting the service you want to inject.
>
> Note that “service” is the name of your reference (it defaults to the
> field name) and that if your reference has a different name (e.g. if you
> change the name of the field) then the name of the property will change too.
>
> For example:
>
> service.target=(foo=bar)
>
>
> Inject me with a MyInterfaceB which has the service property foo equal to
> bar.
>
> All the best,
>
> Tim
>
> On 15 May 2019, at 14:35, Matthias Leinweber <
> Matthias.Leinweber@IDA-Analytics.de> wrote:
>
> Hello Karaf Experts,
>
> i am trying to isolate services from each other.
>
> For Example you have a component:
>
> @Component(
>     configurationPid = "MyInterfacA.factory",
>     configurationPolicy = ConfigurationPolicy.REQUIRE,
> public Class MyInterfaceAImpl implements MyInterfacA{
>
> @Reference
> MyInterfaceB service;
>
>  ...}
>
> During runtime I create multiple services from type MyInterfaceB and
> multiple componentes of MyInterfaceAImpl with configadmin.
> Depending on the configuration of MyInterfaceAImpl I want to filter which
> MyInterfaceB implementation is injected.
>
> I thought about FindHook but there I dont see a way how to get the
> information which service from the bundle is requesting the reference.
>
>
> Is there any chance to do this, or do I have to go for an alternative
> design. Or a better way to isolate services from another?
>
>
> Best regards,
> Matthias
>
>
>

Re: Service Sisibility

Posted by Tim Ward <ti...@paremus.com>.
Declarative Services is amazing, so this is trivially easy to do. In this case you should add the configuration property

service.target

to your configuration dictionary with the value being an LDAP filter selecting the service you want to inject. 

Note that “service” is the name of your reference (it defaults to the field name) and that if your reference has a different name (e.g. if you change the name of the field) then the name of the property will change too.

For example:

service.target=(foo=bar)

Inject me with a MyInterfaceB which has the service property foo equal to bar.

All the best,

Tim

> On 15 May 2019, at 14:35, Matthias Leinweber <Ma...@IDA-Analytics.de> wrote:
> 
> Hello Karaf Experts,
> 
> i am trying to isolate services from each other. 
> 
> For Example you have a component:
> 
> @Component(
>     configurationPid = "MyInterfacA.factory",
>     configurationPolicy = ConfigurationPolicy.REQUIRE,
> public Class MyInterfaceAImpl implements MyInterfacA{
> 
> @Reference
> MyInterfaceB service;
> 
>  ...}
> 
> During runtime I create multiple services from type MyInterfaceB and multiple componentes of MyInterfaceAImpl with configadmin.
> Depending on the configuration of MyInterfaceAImpl I want to filter which MyInterfaceB implementation is injected.
> 
> I thought about FindHook but there I dont see a way how to get the information which service from the bundle is requesting the reference.
> 
> Is there any chance to do this, or do I have to go for an alternative design. Or a better way to isolate services from another?
> 
> 
> Best regards,
> Matthias