Re: [osgi-dev] DS Reference injection order

2018-01-31 Thread BJ Hargrave via osgi-dev
Tim correctly cites the spec regarding the order SCR must process the  elements in the XML. Since you are using annotations, there is one more thing to know. The javadoc for the Reference annotation states:
 
In the generated Component Description for a component, the references must be ordered in ascending lexicographical order (using String.compareTo ) of the reference names. 
 
So you can control the order of the reference elements in the xml by the names of the references.
 
The order of processing reference can be useful if you are using method injection and a method needs to use a previously injected reference. But since you examples show field injection, your component cannot not really observe the order of injection.
 
With 'volatile' you have a dynamic reference which can be updated at any time, so there is no order with respect to other reference.
 
--BJ HargraveSenior Technical Staff Member, IBM // office: +1 386 848 1781OSGi Fellow and CTO of the OSGi Alliance // mobile: +1 386 848 3788hargr...@us.ibm.com
 
 
- Original message -From: Tim Ward via osgi-dev Sent by: osgi-dev-boun...@mail.osgi.orgTo: Thomas Driessen , OSGi Developer Mail List Cc:Subject: Re: [osgi-dev] DS Reference injection orderDate: Wed, Jan 31, 2018 6:43 AM 
Firstly - why do you need to rely on this? It sounds like very fragile code to me and you should probably consider rewriting so that you don’t need to care. However...
 Section 112.5.7 of the compendium says that:

When binding services, the references are processed in the order in which they are specified in the component description. That is, target services from the first specified reference are bound before services from the next specified reference.
 
A static optional service will not be set if it is not satisfied, or will if it is. A dynamic optional service will behave the same way, but it may be unset and reset many times afterwards on other threads. Dynamic services should always be treated with care, whether they are optional or not.
 
Tim
 
On 31 Jan 2018, at 10:50, Thomas Driessen via osgi-dev  wrote: 

Hi,
 
I searched the compendium spec but didn't find what I was looking for.
 
If I have a DS with multiple references to other DS
 
@Component
class Example1{
 
    @Reference
    Example2 e2
 
    @Reference
    Example3 e3
}
 
in which order are the references injected? Is there even a deterministic order?
 
In the above example both references are static/mandatory. What happens if I have a static/mandatory and a dynamic/optional one like this:
 
@Component
class Example1{
 
    @Reference
    Example2 e2
 
    @Reference
    volatile Example3 e3
}
 
Kind regards,
Thomas___OSGi Developer Mail Listosgi-dev@mail.osgi.orghttps://mail.osgi.org/mailman/listinfo/osgi-dev
___OSGi Developer Mail Listosgi-dev@mail.osgi.orghttps://urldefense.proofpoint.com/v2/url?u=https-3A__mail.osgi.org_mailman_listinfo_osgi-2Ddev=DwICAg=jf_iaSHvJObTbx-siA1ZOg=p-HkGsKTJWWSiO-pz0kKXl8ALzmlqvUGeFfgHUZX8ms=P8DWwyvfdkJmQulD35LW62YOdKbDVw6eIWSALp1HIbI=U70U3kBVjtwoTlXKCafEOLUaXN8uM6uEth9KO1zjavY=
 

___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Re: [osgi-dev] DS Reference injection order

2018-01-31 Thread Carsten Ziegeler via osgi-dev
I think there is some sense in ordering references. If you order the
static/required ones before the dynamic ones, you can already use the
services from the first set in the bind method of the dynamic services.
There are some use cases for this, but there are more rare.

Other than that, the below is definitely true

Carsten


Osgi Developer Mail List wrote
> From my understanding the injection order should not be important in any
> way, or said in a better way, you should never rely on it. Your
> component gets satisfied once all required dependencies are resolved. So
> there is no component instance until all references can be resolved and
> injected, therefore you cannot do anything with that component before.
> If you have an optional dependency, the component is satisfied once the
> mandatory dependency can be resolved, the optional one is not taken into
> account here. So you cannot rely anywhere in that component that the
> optional dependency is set at all and always need a null check to be
> safe. And as Tim already said, dynamic services can come and go at any
> time without creating a new component instance, so you always need to be
> careful here.
> 
>  
> 
> Mit freundlichen Grüßen / Best regards
> 
> *Dirk Fauth
> *
> Automotive Service Solutions, ESI application (AA-AS/EIS2-EU)
> Robert Bosch GmbH | Postfach 11 29 | 73201 Plochingen | GERMANY |
> www.bosch.com 
> Tel. +49 7153 666-1155 | dirk.fa...@de.bosch.com
> 
> 
> Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000;
> Aufsichtsratsvorsitzender: Franz Fehrenbach; Geschäftsführung: Dr.
> Volkmar Denner,
> Prof. Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan
> Hartung, Dr. Markus Heyn, Dr. Dirk Hoheisel,
> Christoph Kübel, Uwe Raschke, Peter Tyroller
> 
> 
> *Von:*osgi-dev-boun...@mail.osgi.org
> [mailto:osgi-dev-boun...@mail.osgi.org] *Im Auftrag von *Tim Ward via
> osgi-dev
> *Gesendet:* Mittwoch, 31. Januar 2018 12:43
> *An:* Thomas Driessen ; OSGi Developer
> Mail List 
> *Betreff:* Re: [osgi-dev] DS Reference injection order
> 
>  
> 
> Firstly - why do you need to rely on this? It sounds like very fragile
> code to me and you should probably consider rewriting so that you don’t
> need to care. However...
> 
>  
> 
> Section 112.5.7 of the compendium says that:
> 
> /
> When binding services, the references are processed in the order in
> which they are specified in the component description. That is,
> target services from the first specified reference are bound
> before services from the next specified reference./
> 
>  
> 
> A static optional service will not be set if it is not satisfied, or
> will if it is. A dynamic optional service will behave the same way, but
> it may be unset and reset many times afterwards on other threads.
> Dynamic services should always be treated with care, whether they are
> optional or not.
> 
>  
> 
> Tim
> 
> 
> 
> On 31 Jan 2018, at 10:50, Thomas Driessen via osgi-dev
> > wrote:
> 
>  
> 
> Hi,
> 
>  
> 
> I searched the compendium spec but didn't find what I was looking for.
> 
>  
> 
> If I have a DS with multiple references to other DS
> 
>  
> 
> @Component
> 
> class Example1{
> 
>  
> 
>     @Reference
> 
>     Example2 e2
> 
>  
> 
>     @Reference
> 
>     Example3 e3
> 
> }
> 
>  
> 
> in which order are the references injected? Is there even a
> deterministic order?
> 
>  
> 
> In the above example both references are static/mandatory. What
> happens if I have a static/mandatory and a dynamic/optional one like
> this:
> 
>  
> 
> @Component
> 
> class Example1{
> 
>  
> 
>     @Reference
> 
>     Example2 e2
> 
>  
> 
>     @Reference
> 
>     volatile Example3 e3
> 
> }
> 
>  
> 
> Kind regards,
> 
> Thomas
> 
> ___
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org 
> https://mail.osgi.org/mailman/listinfo/osgi-dev
> 
>  
> 
> 
> 
> ___
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev
> 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziege...@apache.org
___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Re: [osgi-dev] DS Reference injection order

2018-01-31 Thread Fauth Dirk (AA-AS/EIS2-EU) via osgi-dev
From my understanding the injection order should not be important in any way, 
or said in a better way, you should never rely on it. Your component gets 
satisfied once all required dependencies are resolved. So there is no component 
instance until all references can be resolved and injected, therefore you 
cannot do anything with that component before. If you have an optional 
dependency, the component is satisfied once the mandatory dependency can be 
resolved, the optional one is not taken into account here. So you cannot rely 
anywhere in that component that the optional dependency is set at all and 
always need a null check to be safe. And as Tim already said, dynamic services 
can come and go at any time without creating a new component instance, so you 
always need to be careful here.

Mit freundlichen Grüßen / Best regards

Dirk Fauth

Automotive Service Solutions, ESI application (AA-AS/EIS2-EU)
Robert Bosch GmbH | Postfach 11 29 | 73201 Plochingen | GERMANY | 
www.bosch.com
Tel. +49 7153 666-1155 | dirk.fa...@de.bosch.com

Sitz: Stuttgart, Registergericht: Amtsgericht Stuttgart, HRB 14000;
Aufsichtsratsvorsitzender: Franz Fehrenbach; Geschäftsführung: Dr. Volkmar 
Denner,
Prof. Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr. 
Markus Heyn, Dr. Dirk Hoheisel,
Christoph Kübel, Uwe Raschke, Peter Tyroller


Von: osgi-dev-boun...@mail.osgi.org [mailto:osgi-dev-boun...@mail.osgi.org] Im 
Auftrag von Tim Ward via osgi-dev
Gesendet: Mittwoch, 31. Januar 2018 12:43
An: Thomas Driessen ; OSGi Developer Mail List 

Betreff: Re: [osgi-dev] DS Reference injection order

Firstly - why do you need to rely on this? It sounds like very fragile code to 
me and you should probably consider rewriting so that you don’t need to care. 
However...

Section 112.5.7 of the compendium says that:

When binding services, the references are processed in the order in which they 
are specified in the component description. That is, target services from the 
first specified reference are bound before services from the next specified 
reference.

A static optional service will not be set if it is not satisfied, or will if it 
is. A dynamic optional service will behave the same way, but it may be unset 
and reset many times afterwards on other threads. Dynamic services should 
always be treated with care, whether they are optional or not.

Tim


On 31 Jan 2018, at 10:50, Thomas Driessen via osgi-dev 
> wrote:

Hi,

I searched the compendium spec but didn't find what I was looking for.

If I have a DS with multiple references to other DS

@Component
class Example1{

@Reference
Example2 e2

@Reference
Example3 e3
}

in which order are the references injected? Is there even a deterministic order?

In the above example both references are static/mandatory. What happens if I 
have a static/mandatory and a dynamic/optional one like this:

@Component
class Example1{

@Reference
Example2 e2

@Reference
volatile Example3 e3
}

Kind regards,
Thomas
___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

[osgi-dev] DS Reference injection order

2018-01-31 Thread Thomas Driessen via osgi-dev

Hi,

I searched the compendium spec but didn't find what I was looking for.

If I have a DS with multiple references to other DS

@Component
class Example1{

@Reference
Example2 e2

@Reference
Example3 e3
}

in which order are the references injected? Is there even a 
deterministic order?


In the above example both references are static/mandatory. What happens 
if I have a static/mandatory and a dynamic/optional one like this:


@Component
class Example1{

@Reference
Example2 e2

@Reference
volatile Example3 e3
}

Kind regards,
Thomas___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev