> 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 <mailto:osgi-dev@mail.osgi.org>
> https://mail.osgi.org/mailman/listinfo/osgi-dev 
> <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

Reply via email to