[
https://issues.apache.org/jira/browse/FELIX-5861?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17169191#comment-17169191
]
Robert Varga commented on FELIX-5861:
-------------------------------------
The spec is not clear on the ordering here: both the factory component is
becoming unsatisfied (hence tearing down the ComponentFactory) and the
individual component configurations are becoming unsatisfied (hence tearing
down the ComponentInstances).
I think this should be the first option, as it ties in clearly with lifecycle.
Whoever was using the ComponentFactory will see it unbound and will know to
release the ComponentInstances. With static references, this will even cause
that component to deactivate. If that component fails to clean the component
instances up, it should be okay to clear them automatically *after* it was
given the chance.
> ComponentInstances are disposed before disposal of ComponentFactory
> -------------------------------------------------------------------
>
> Key: FELIX-5861
> URL: https://issues.apache.org/jira/browse/FELIX-5861
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Reporter: Erwin Bronkhorst
> Priority: Major
>
> When a bundle that contains a {{ComponentFactory}} is stopped, all
> {{ComponentInstances}} in the bundle are disposed first, and after that the
> {{ComponentFactory}} itself [1]. I think it is better if this would be the
> other way around.
> Given a situation in which component X has a static mandatory binding to the
> {{ComponentFactory}} Y and created {{ComponentInstance}} Z using
> {{y.newInstance()}}. If the bundle containing Y is stopped, the following
> order of events happens:
> # All {{ComponentInstances}} created by Y are disposed.
> # Y is going to be disposed, and for that the SCR deactivates component X.
> # The unbind-methods in X are called.
> # The {{ComponentFactory}} Y is deactivated and disposed.
> As far as I know, component X get no trigger of event 1. This means that the
> {{ComponentInstance}} Z can be disposed without component X knowing this. I
> have seen a situation in which component X tries to use {{ComponentInstance}}
> Z after event 1, but before event 2 resulting in a runtime exception.
> I think that, because component X created the {{ComponentInstance}} Z,
> component X is responsible of disposing the instance. It should dispose the
> created {{ComponentInstances}} when X is deactivated. Of course, to prevent
> garbage in the registry, it is wise to dispose all remaining
> {{ComponentInstances}} when the bundle is stopped, in case some components
> failed to cleanup correctly.
> So in short: who is the owner of a {{ComponentInstances}}, created by
> {{ComponentFactory.newInstance()}} and who is responsible for cleaning it up?
> - If it is the component that called {{newInstance()}}, I think the dispose
> of the factory should be done before the dispose on the (remaining)
> {{ComponentInstances}}. This way, the unbind of the factory is called before
> the {{ComponentInstance}} is disposed.
> - If it is the {{ComponentFactory}} that created the instance, is there a
> possibility to get a notification when the {{ComponentInstance}} is disposed,
> so the application can respond to it?
> [1]
> [https://github.com/apache/felix/blob/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java#L350]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)