[
https://issues.apache.org/jira/browse/SLING-4417?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14528107#comment-14528107
]
Konrad Windszus commented on SLING-4417:
----------------------------------------
According to the OSGi spec the lifecycle of a delayed component is not that
much different from an immediate component. The only difference should be the
point in time it is activated (but not the deactivation of the component). The
difference is described in OSGi Compendium 4.3 $112.5.4:
{quote}
The activation of a component configuration must be delayed until its service
is requested. When the service is requested, if the service has the
servicefactory attribute set to true, SCR must create and activate a unique
component configuration for each bundle requesting the service. Otherwise, SCR
must activate a single component configuration which is used by all bundles
requesting the service. A component instance can determine the bundle it was
activated for by calling the getUsingBundle() method on the Component Context.
{quote}
{quote}
If the service registered by a component configuration becomes unused because
there are no more bundles using it, then SCR should deactivate that component
configuration. This allows SCR implementations to eagerly reclaim activated
component configurations.
{quote}
The diagrams in that paragraph depict that nicely.
The deferred activation should be no problem but the fact that the references
to the HealthChecks are no longer used once the healthcheck was executed is a
problem. This leads to the instance being lost. Why do you not keep those
service references e.g. in the executor. That would prevent the OSGi container
from deactivating those components.
> HC Annotation should allow to configure "immediate" SCR property
> ----------------------------------------------------------------
>
> Key: SLING-4417
> URL: https://issues.apache.org/jira/browse/SLING-4417
> Project: Sling
> Issue Type: New Feature
> Components: Health Check
> Reporter: Georg Henzler
> Attachments: SLING-4417-HC-Annotation-with-immediate-setting.patch
>
>
> When using @SlingHealthCheck at the moment, the "immediate" property is left
> to "false" in the SCR descriptor which causes the component object to be
> created on every call of the health check (making it impossible to keep some
> state in a private member variable if desired).
> Let's make the immediate property configurable (the same way it would be
> provided in the @Component annotation) and make immediate="true" the default
> (this is a slight change in the behaviour that will not break existing code)
> for the following reasons:
> - It's more intuitive to think of a HC as singleton (and hence be able to
> keep some instance variables)
> - It's a tiny little bit better from a performance perspective (the instance
> does not have to be created on each execution)
> The attached patch includes the (fairly simple) change to
> annotation(-processor) and the change for two sample components that were
> using @Component because of this issue.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)