Hi Clement,

thank you very much for your fast reply.

I have forgotten to mention, that the service BETA is stated as 'optional' 
within ALPHA (@Requires(optional=true)).

Thus the injected proxy object returns NULL on calling the method 'getData' of 
BETA, if BETA is unavailable.
Only the helper object (WORKER) receives the RuntimeException.

It is a little confusing, as this should be the same proxy object !?

I could make the WORKER class a Component, but how can I create the actual 
object instance during runtime for a Component ?
Or is there a better way to accomplish this ?

Regards,
Thorsten

On 15.06.2011, at 09:21, Clement Escoffier wrote:

> 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]
> 
> 


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

Reply via email to