Hi,

On 21 nov. 2013, at 14:40, Benjamin Debeerst <[email protected]> wrote:

> Hello all,
> 
> While working with some iPOJO components and mandatory references I stumbled 
> upon the warning "The dependency is not optional, however no service can be 
> injected", followed by an NPE.
> 
> The situation is fairly simple: I have a component A with a mandatory 
> reference to service B. When service B goes away, it is first removed from my 
> component A, but the @Invalidate callback of A is only called after the fact 
> - effectively preventing me of doing a proper cleanup and provoking the NPE. 
> This gets even more complicated when component A has started asynchronous 
> jobs working with B, because it can't shut down those jobs on time.
> 
> I found a thread from 2009 on this list that treats more or less the same 
> problem [1], Clement wrote as answer:
> 
> "When a required (not optional) service leaves, it invalidates the instance. 
> If this instance has an 'invalidate' callback, this callback is called. The 
> callback is called after its unregistration, that's why the service is no 
> more available. So, invalidate callbacks must be developed defensively to 
> check service availability."
> 
> I find this rather counter-intuitive. Why is the invalidate callback called 
> after the fact? Yet, iPOJO has the information of the leaving mandatory 
> reference B on time, since it can call the @Unbind callback on time. I am 
> also comparing to Declarative Services, which guarantees that it will 
> deactivate your component before it takes away any mandatory references. I 
> found it a big advantage of iPOJO (compared to DS) to be able to drop the 
> implementation of the bind/unbind glue and have the references injected in 
> the fields directly. Now I do not only have write the glue again, moreover I 
> have to delegate the unbind call to the invalidate() method for each 
> mandatory reference in my component. 
> 
> The thing is that I do not see any advantage of iPOJO's call order compared 
> to DS's call order. Are there specific reasons for this?

I agree this choice is debatable, and is going to change in iPOJO 2.0.  The 
@Invalidate callback should be called while the services are still accessible 
to ease the cleanup process.

So, it’s going to change soon.

Regards,

Clement



> 
> Regards,
> Benjamin
> 
> [1] 
> http://mail-archives.apache.org/mod_mbox/felix-users/200908.mbox/%[email protected]%3E
> Т���������������������������������������������������������������������ХF�V�7V'67&�&R�R���âW6W'2�V�7V'67&�&TfVƗ��6�R��&pФf�"FF�F����6����G2�R���âW6W'2ֆV�fVƗ��6�R��&p�


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

Reply via email to