You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Jonathan Vila Lopez <jo...@gmail.com> on 2016/01/07 11:10:57 UTC

SCR annotations documentation for list of services injection

Hi all.

I would like to find the documentation about Felix SCR annotation Reference
that explains the injection for a list of services.

@Reference
List<ArticleFilter> list;

​Is that correct ?

I've found in other places something like :

@Reference(referenceInterface = AspectRatioCalculator.class,
cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy =
ReferencePolicy.DYNAMIC)
private final Map<String, AspectRatioCalculator>
aspectRatioCalculators = new ConcurrentHashMap<String,
AspectRatioCalculator>();

protected void bindAspectRatioCalculators(final AspectRatioCalculator arc) {
    this.aspectRatioCalculators.put(arc.getResourceType(), arc);
}

protected void unbindAspectRatioCalculators(final AspectRatioCalculator arc) {
    this.aspectRatioCalculators.remove(arc.getResourceType());
}


​And in this last case I don't know if the bind/unbind methods are a must,
if not I can use a list of services injections using a Map ? if so, what is
the first type String for ?....

​So, is there all this information written in any place in the
documentation ?

Thank you.​



[image: Inline image 2]

* Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
<http://www.linkedin.com/in/jonathanvila>*

* jonathan.vila@gmail.com <jo...@gmail.com>*

Re: SCR annotations documentation for list of services injection

Posted by Sander van Beek <sv...@tricode.nl>.
Hi Jonathan,

You can use a list instead of a map, but you need to specify the
cardinality (as seen in the second example). If I remember correctly the
bind/unbind methods will be generated if you dont explicitly declare them.
Hope this helps, you are right that the documentation is a bit vague about
this.

Cheers,
Sander

2016-01-07 11:10 GMT+01:00 Jonathan Vila Lopez <jo...@gmail.com>:

> Hi all.
>
> I would like to find the documentation about Felix SCR annotation
> Reference that explains the injection for a list of services.
>
> @Reference
> List<ArticleFilter> list;
>
> ​Is that correct ?
>
> I've found in other places something like :
>
> @Reference(referenceInterface = AspectRatioCalculator.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
> private final Map<String, AspectRatioCalculator> aspectRatioCalculators = new ConcurrentHashMap<String, AspectRatioCalculator>();
>
> protected void bindAspectRatioCalculators(final AspectRatioCalculator arc) {
>     this.aspectRatioCalculators.put(arc.getResourceType(), arc);
> }
>
> protected void unbindAspectRatioCalculators(final AspectRatioCalculator arc) {
>     this.aspectRatioCalculators.remove(arc.getResourceType());
> }
>
>
> ​And in this last case I don't know if the bind/unbind methods are a must,
> if not I can use a list of services injections using a Map ? if so, what is
> the first type String for ?....
>
> ​So, is there all this information written in any place in the
> documentation ?
>
> Thank you.​
>
>
>
> [image: Inline image 2]
>
> * Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
> <http://www.linkedin.com/in/jonathanvila>*
>
> * jonathan.vila@gmail.com <jo...@gmail.com>*
>
>
>
>


-- 
Met vriendelijke groet,
*Tricode Professional Services BV*

*Sander van Beek*
*Teamlead AEM / Teamlead Servicedesk*
*E* svbeek@tricode.nl  |  *T* +31 318 559210 <+31%20318%20559210>  |  *M* +31
6 2724 9560 <+31628395109> (gewijzigd!) |  *W* www.tricode.nl
*S* linkedin <http://www.linkedin.com/company/tricode> | slideshare
<http://www.slideshare.net/Tricode> | twitter <https://twitter.com/Tricode>
| google+ <https://plus.google.com/+tricode> | facebook
<https://www.facebook.com/Tricode> Tricode Professional Services BV;  De
Schutterij 12; 3905 PL Veenendaal, Netherlands
<http://www.tricode.nl/aem> <http://www.tricode.nl/magnolia>
<http://www.tricode.nl/ishop>

-- 
De inhoud van dit emailbericht is strikt vertrouwelijk en uitsluitend 
bestemd om gelezen te worden door de geadresseerde. Wij verzoeken u 
derhalve dit bericht direct aan de geadresseerde te overhandigen. Indien 
deze email per vergissing door u is ontvangen verzoeken wij u contact met 
ons op te nemen. Iedere openbaarmaking, verspreiding of vermenigvuldiging 
van dit emailbericht is strikt verboden. Iedere aansprakelijkheid is 
beperkt tot het bedrag dat in het desbetreffende geval onder onze 
beroepsaansprakelijkheidsverzekering wordt uitbetaald. 

The contents of this email is strictly personal and confidential and is 
only intended for the use by the adressee named above. We request you tot 
deliver this email immediately to the adressee. If you have received this 
email in error, please notify us. Publication, circulation, or 
multiplication of this email is strictly prohibited. Any liability shall be 
limited to the amount which is paid under the Firm's professional Liability 
Policy in the matter concerned.

Re: SCR annotations documentation for list of services injection

Posted by Carsten Ziegeler <cz...@apache.org>.
You find the official annotations in the release 6 compendium spec
https://www.osgi.org/developer/specifications/ (chapter Declarative
Services)

A simple intro can be found here: http://blog.osoco.de/?p=91

The differences are, the official ones support field references natively
including references to multiple services. (Apache Felix SCR only for
unary with byte code manipulation at build time).
The DS annotations have a nicer way of describing the component
configuration and metatype.
The DS annotations support release 6 of the Declarative Service
specification, the Apache Felix SCR ones only the features of release 5.

We consider the Apache Felix SCR annotations to be deprecated and
suggest people to switch to the official ones.

Regards
Carsten

Jonathan Vila Lopez wrote
> Hi, thank you for your help
> 
> @cziegeler which are the official DS annotations ? which are the
> differences between those and SCR ones ?
> 
> @svbeek What do you mean by "If I remember correctly the
> bind/unbind methods will be generated if you dont explicitly declare them.
> ​" ? If I use the injection with a Map, the auto generated bind method,
> what will it put in the first argument <String, -interface-> ? or only
> it works with Lists by default ?
> 
> Thank you​
> 
> 
> Inline image 2
> 
> 	
> 
> * Jonathan Vila  
>  **_*_<https://www.twitter.com/jonathan_vila>_**_ _**_<http://www.linkedin.com/in/jonathanvila>_*_**
> **_ jonathan.vila@gmail.com <ma...@gmail.com>
> _*
> 
>  
> 
> 
> On Thu, Jan 7, 2016 at 11:27 AM, Carsten Ziegeler <cziegeler@apache.org
> <ma...@apache.org>> wrote:
> 
>     Hi,
> 
>     with the Felix SCR annotations, @Reference on a field only handles unary
>     cardinality. If you want to handle multiple cardinality you have to
>     implement the bind/unbind methods similar to the example you gave.
> 
>     In general, I suggest to use the official DS annotations instead of the
>     SCR ones, as the latest version from R6 has now finally all the features
>     from the Felix SCR annotations (in slightly different flavour) and also
>     supports the kind of field annotations you're looking for.
> 
>     Regards
>     Carsten
> 
>     Jonathan Vila Lopez wrote
>     > Hi all.
>     >
>     > I would like to find the documentation about Felix SCR annotation
>     > Reference that explains the injection for a list of services.
>     >
>     >     @Reference
>     >     List<ArticleFilter> list;
>     >
>     > ​Is that correct ?
>     >
>     > I've found in other places something like :
>     >
>     > @Reference(referenceInterface = AspectRatioCalculator.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
>     > private final Map<String, AspectRatioCalculator> aspectRatioCalculators = new ConcurrentHashMap<String, AspectRatioCalculator>();
>     >
>     > protected void bindAspectRatioCalculators(final AspectRatioCalculator arc) {
>     >     this.aspectRatioCalculators.put(arc.getResourceType(), arc);
>     > }
>     >
>     > protected void unbindAspectRatioCalculators(final AspectRatioCalculator arc) {
>     >     this.aspectRatioCalculators.remove(arc.getResourceType());
>     > }
>     >
>     >
>     > ​And in this last case I don't know if the bind/unbind methods are a
>     > must, if not I can use a list of services injections using a Map ? if
>     > so, what is the first type String for ?....
>     >
>     > ​So, is there all this information written in any place in the
>     > documentation ?
>     >
>     > Thank you.​
>     >
>     >
>     >
>     > Inline image 2
>     >
>     >
>     >
>     > * Jonathan Vila
>     >  **_*_<https://www.twitter.com/jonathan_vila>_**_
>     _**_<http://www.linkedin.com/in/jonathanvila>_*_**
>     > **_ jonathan.vila@gmail.com <ma...@gmail.com>
>     <mailto:jonathan.vila@gmail.com <ma...@gmail.com>>
>     > _*
>     >
>     >
>     >
> 
> 
> 
>     --
>     Carsten Ziegeler
>     Adobe Research Switzerland
>     cziegeler@apache.org <ma...@apache.org>
> 
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>     <ma...@felix.apache.org>
>     For additional commands, e-mail: users-help@felix.apache.org
>     <ma...@felix.apache.org>
> 
> 


 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: SCR annotations documentation for list of services injection

Posted by Jonathan Vila Lopez <jo...@gmail.com>.
Hi, thank you for your help

@cziegeler which are the official DS annotations ? which are the
differences between those and SCR ones ?

@svbeek What do you mean by "If I remember correctly the
bind/unbind methods will be generated if you dont explicitly declare them.
​" ? If I use the injection with a Map, the auto generated bind method,
what will it put in the first argument <String, -interface-> ? or only it
works with Lists by default ?

Thank you​


[image: Inline image 2]

* Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
<http://www.linkedin.com/in/jonathanvila>*

* jonathan.vila@gmail.com <jo...@gmail.com>*




On Thu, Jan 7, 2016 at 11:27 AM, Carsten Ziegeler <cz...@apache.org>
wrote:

> Hi,
>
> with the Felix SCR annotations, @Reference on a field only handles unary
> cardinality. If you want to handle multiple cardinality you have to
> implement the bind/unbind methods similar to the example you gave.
>
> In general, I suggest to use the official DS annotations instead of the
> SCR ones, as the latest version from R6 has now finally all the features
> from the Felix SCR annotations (in slightly different flavour) and also
> supports the kind of field annotations you're looking for.
>
> Regards
> Carsten
>
> Jonathan Vila Lopez wrote
> > Hi all.
> >
> > I would like to find the documentation about Felix SCR annotation
> > Reference that explains the injection for a list of services.
> >
> >     @Reference
> >     List<ArticleFilter> list;
> >
> > ​Is that correct ?
> >
> > I've found in other places something like :
> >
> > @Reference(referenceInterface = AspectRatioCalculator.class, cardinality
> = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
> > private final Map<String, AspectRatioCalculator> aspectRatioCalculators
> = new ConcurrentHashMap<String, AspectRatioCalculator>();
> >
> > protected void bindAspectRatioCalculators(final AspectRatioCalculator
> arc) {
> >     this.aspectRatioCalculators.put(arc.getResourceType(), arc);
> > }
> >
> > protected void unbindAspectRatioCalculators(final AspectRatioCalculator
> arc) {
> >     this.aspectRatioCalculators.remove(arc.getResourceType());
> > }
> >
> >
> > ​And in this last case I don't know if the bind/unbind methods are a
> > must, if not I can use a list of services injections using a Map ? if
> > so, what is the first type String for ?....
> >
> > ​So, is there all this information written in any place in the
> > documentation ?
> >
> > Thank you.​
> >
> >
> >
> > Inline image 2
> >
> >
> >
> > * Jonathan Vila
> >  **_*_<https://www.twitter.com/jonathan_vila>_**_ _**_<
> http://www.linkedin.com/in/jonathanvila>_*_**
> > **_ jonathan.vila@gmail.com <ma...@gmail.com>
> > _*
> >
> >
> >
>
>
>
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Re: SCR annotations documentation for list of services injection

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

with the Felix SCR annotations, @Reference on a field only handles unary
cardinality. If you want to handle multiple cardinality you have to
implement the bind/unbind methods similar to the example you gave.

In general, I suggest to use the official DS annotations instead of the
SCR ones, as the latest version from R6 has now finally all the features
from the Felix SCR annotations (in slightly different flavour) and also
supports the kind of field annotations you're looking for.

Regards
Carsten

Jonathan Vila Lopez wrote
> Hi all.
> 
> I would like to find the documentation about Felix SCR annotation
> Reference that explains the injection for a list of services.
> 
>     @Reference
>     List<ArticleFilter> list;
> 
> ​Is that correct ?
> 
> I've found in other places something like :
> 
> @Reference(referenceInterface = AspectRatioCalculator.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
> private final Map<String, AspectRatioCalculator> aspectRatioCalculators = new ConcurrentHashMap<String, AspectRatioCalculator>();
> 
> protected void bindAspectRatioCalculators(final AspectRatioCalculator arc) {
>     this.aspectRatioCalculators.put(arc.getResourceType(), arc);
> }
> 
> protected void unbindAspectRatioCalculators(final AspectRatioCalculator arc) {
>     this.aspectRatioCalculators.remove(arc.getResourceType());
> }
> 
> 
> ​And in this last case I don't know if the bind/unbind methods are a
> must, if not I can use a list of services injections using a Map ? if
> so, what is the first type String for ?....
> 
> ​So, is there all this information written in any place in the
> documentation ?
> 
> Thank you.​
> 
> 
> 
> Inline image 2
> 
> 	
> 
> * Jonathan Vila  
>  **_*_<https://www.twitter.com/jonathan_vila>_**_ _**_<http://www.linkedin.com/in/jonathanvila>_*_**
> **_ jonathan.vila@gmail.com <ma...@gmail.com>
> _*
> 
>  
> 


 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org