Re: [osgi-dev] ComponentServiceObjects vs ServiceObjects

2019-02-19 Thread Raymond Auge via osgi-dev
Thomas,

You can only use ComponentServiceReference where you have @Reference.

In other words, if you create a raw service tracker, or if you get service
directly (and I sincerely hope not), the you _must_ use ServiceObjects.

In a few months when you ultimately switch over to CDI integration ;)
you'll then use org.osgi.service.cdi.reference.BeanServiceObjects with the
same goal as ComponentServiceObjects.

:)

- Ray

On Tue, Feb 19, 2019 at 2:07 PM Thomas Driessen via osgi-dev <
osgi-dev@mail.osgi.org> wrote:

> Hi Tim,
>
> as always this is super informative :) Thanks.
>
> Should I then use ComponentServiceObjects too when I'm not in the context
> of a @Component annotated class?
> In my last sketch for the OSGi integration in Vaadin Flow I used
> ServiceObjects instead. Would ComponentServiceObjects be better here?
>
> This is the class I'm talking about:
> https://github.com/Sandared/flow-osgi/blob/master/flow.osgi.integration/src/main/java/io/jatoms/flow/osgi/integration/v2/OSGiInstantiatorV2.java
>
> Kind regards,
> Thomas
>
> -- Originalnachricht --
> Von: "Tim Ward" 
> An: "Thomas Driessen" ; "OSGi Developer
> Mail List" 
> Gesendet: 19.02.2019 14:02:21
> Betreff: Re: [osgi-dev] ComponentServiceObjects vs ServiceObjects
>
> As I get it ComponentServiceObjects are just for use within Components and
> are obtained vie @Reference?
>
>
> Yes - you should *always* use ComponentServiceObjects if you want to get
> on-demand instances of a prototype scope service inside your DS component.
>
> But why are not ServiceObjects used for this?
>
>
> ServiceObjects is a low-level API. You are responsible for ensuring that
> *every* call to get is balanced by a call to unget. This gives your
> component a big tidy-up job in its deactivate method (and other places as
> necessary). If you use ComponentServiceObjects then DS is able to track all
> of the instances that you’ve created and make sure that they all get
> released automatically if your component is deactivated or the reference is
> rebound (for example with a greedy dynamic mandatory reference).
>
> ComponentServiceObjects is therefore much safer to use than ServiceObjects
> as you don’t need to be worried about the mess that could be ongoing when
> your component stops. Note that if your component can create a potentially
> unlimited number of service instances from the ComponentServiceObjects you
> must still make sure to release instances that you create. If you fail to
> do this you will run out of memory.
>
> I hope this helps.
>
> Tim
>
> On 19 Feb 2019, at 13:53, Thomas Driessen via osgi-dev <
> osgi-dev@mail.osgi.org> wrote:
>
> Hi,
>
> can someone explain to me the difference between ComponentServiceObjects
> and ServiceObjects and when to use which?
>
> As I get it ComponentServiceObjects are just for use within Components and
> are obtained vie @Reference? But why are not ServiceObjects used for this?
>
> 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



-- 
*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)
___
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Re: [osgi-dev] ComponentServiceObjects vs ServiceObjects

2019-02-19 Thread Thomas Driessen via osgi-dev

Hi Tim,

as always this is super informative :) Thanks.

Should I then use ComponentServiceObjects too when I'm not in the 
context of a @Component annotated class?
In my last sketch for the OSGi integration in Vaadin Flow I used 
ServiceObjects instead. Would ComponentServiceObjects be better here?


This is the class I'm talking about: 
https://github.com/Sandared/flow-osgi/blob/master/flow.osgi.integration/src/main/java/io/jatoms/flow/osgi/integration/v2/OSGiInstantiatorV2.java


Kind regards,
Thomas

-- Originalnachricht --
Von: "Tim Ward" 
An: "Thomas Driessen" ; "OSGi Developer 
Mail List" 

Gesendet: 19.02.2019 14:02:21
Betreff: Re: [osgi-dev] ComponentServiceObjects vs ServiceObjects

As I get it ComponentServiceObjects are just for use within Components 
and are obtained vie @Reference?


Yes - you should *always* use ComponentServiceObjects if you want to 
get on-demand instances of a prototype scope service inside your DS 
component.



But why are not ServiceObjects used for this?


ServiceObjects is a low-level API. You are responsible for ensuring 
that *every* call to get is balanced by a call to unget. This gives 
your component a big tidy-up job in its deactivate method (and other 
places as necessary). If you use ComponentServiceObjects then DS is 
able to track all of the instances that you’ve created and make sure 
that they all get released automatically if your component is 
deactivated or the reference is rebound (for example with a greedy 
dynamic mandatory reference).


ComponentServiceObjects is therefore much safer to use than 
ServiceObjects as you don’t need to be worried about the mess that 
could be ongoing when your component stops. Note that if your component 
can create a potentially unlimited number of service instances from the 
ComponentServiceObjects you must still make sure to release instances 
that you create. If you fail to do this you will run out of memory.


I hope this helps.

Tim

On 19 Feb 2019, at 13:53, Thomas Driessen via osgi-dev 
 wrote:


Hi,

can someone explain to me the difference between 
ComponentServiceObjects and ServiceObjects and when to use which?


As I get it ComponentServiceObjects are just for use within Components 
and are obtained vie @Reference? But why are not ServiceObjects used 
for this?


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

Re: [osgi-dev] ComponentServiceObjects vs ServiceObjects

2019-02-19 Thread Tim Ward via osgi-dev
> As I get it ComponentServiceObjects are just for use within Components and 
> are obtained vie @Reference?

Yes - you should *always* use ComponentServiceObjects if you want to get 
on-demand instances of a prototype scope service inside your DS component.

> But why are not ServiceObjects used for this?

ServiceObjects is a low-level API. You are responsible for ensuring that 
*every* call to get is balanced by a call to unget. This gives your component a 
big tidy-up job in its deactivate method (and other places as necessary). If 
you use ComponentServiceObjects then DS is able to track all of the instances 
that you’ve created and make sure that they all get released automatically if 
your component is deactivated or the reference is rebound (for example with a 
greedy dynamic mandatory reference).

ComponentServiceObjects is therefore much safer to use than ServiceObjects as 
you don’t need to be worried about the mess that could be ongoing when your 
component stops. Note that if your component can create a potentially unlimited 
number of service instances from the ComponentServiceObjects you must still 
make sure to release instances that you create. If you fail to do this you will 
run out of memory.

I hope this helps.

Tim

> On 19 Feb 2019, at 13:53, Thomas Driessen via osgi-dev 
>  wrote:
> 
> Hi,
> 
> can someone explain to me the difference between ComponentServiceObjects and 
> ServiceObjects and when to use which?
> 
> As I get it ComponentServiceObjects are just for use within Components and 
> are obtained vie @Reference? But why are not ServiceObjects used for this?
> 
> 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] ComponentServiceObjects vs ServiceObjects

2019-02-19 Thread Thomas Driessen via osgi-dev

Hi,

can someone explain to me the difference between ComponentServiceObjects 
and ServiceObjects and when to use which?


As I get it ComponentServiceObjects are just for use within Components 
and are obtained vie @Reference? But why are not ServiceObjects used for 
this?


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