Hi,

On 14.06.2011, at 23:51, Thorsten Sprenger wrote:

> Hi,
> 
> I have a question concerning iPOJO and services with using a service within a 
> subclass object of another service.
> The special case for which I need support is, when the accessed service 
> becomes unavailable.
> 
> I have two services ALPHA and BETA with a method 'getData'.
> The service ALPHA is spawning several objects (class WORKER, part of the 
> ALPHA bundle) during runtime. Each WORKER object needs to access the service 
> BETA.
> 
> How can this be accomplished correctly ?
> 
> The service ALPHA has a reference to BETA via field injection and I provide 
> the BETA object reference to each spawned WORKER object upon creation of the 
> WORKER object.
> 
> If I access BETA from ALPHA directly, everything works as expected: if BETA 
> becomes unavailable, getData returns NULL.
> But if I access BETA from the WORKER object, calling getData will throw a 
> RuntimeException if BETA becomes unavailable.
> 
> Is this the correct behavior ?

Yes it is. The reason is that iPOJO injects proxies by default. Using proxies 
allow you to give a service object to inner classes or helper objects. If the 
service on which the proxy delegates, becomes unavailable, the proxy cannot 
delegate to the service anymore. The main component instance is invalidated, 
but for inner classes (or helper objects), a RuntimeException is thrown because 
iPOJO does not control the lifecycle of those objects.

Regards,

Clement

> How should I change my code or design, that I can access services from a 
> subclass object ?
> 
> Many thanks in advance !
> 
> Regards,
> Thorsten
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to