You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Stefan Seifert (JIRA)" <ji...@apache.org> on 2014/07/01 00:07:24 UTC

[jira] [Resolved] (SLING-3717) Sling Models: Add support for JSR-250 @PreDestroy annotation

     [ https://issues.apache.org/jira/browse/SLING-3717?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert resolved SLING-3717.
-----------------------------------

    Resolution: Won't Fix

after thinking about this and looking in the existing Sling Models implementation i thinks it's not so easy to implement it and not worth implementing exotic or dangerous workaround to get it running.

the problem is - unlike for example a bean in Spring - the model instances are not managed thorough its lifetime by sling models, but only instantiated. once this is done the instance is only kept by the calling code. cleaning up resources by injectors is handled by enqueuing phantom references to the model instance and implementations of DisposalCallback - but this works only for "thirdparty references" like OSGi service reference, not for the object itself and it's @PreDestroy method. By design its not possible to get a object from a phantom reference queue, because its finalized before it's put into this queue, so the objects and it's @PreDestroy methods are no longer available at the time where the DisposalCallback instances are called.

workaround like wrapping the model object in another object with a finalize method are dangerous, because when the @PreDestroy code is invalid it can lead to resurrecting the dead model object etc.

so - until we have a real usecase, that does not involve resources from injectors (which are handled by the DisposalCallback interface), we should postpone this improvement request.

> Sling Models: Add support for JSR-250 @PreDestroy annotation
> ------------------------------------------------------------
>
>                 Key: SLING-3717
>                 URL: https://issues.apache.org/jira/browse/SLING-3717
>             Project: Sling
>          Issue Type: Improvement
>          Components: Extensions
>            Reporter: Stefan Seifert
>            Priority: Minor
>
> Sling Models already supports a @PostConstruct annotation.
> It would be reasonable to support an optional @PreDestroy annotation as well.
> if i find the time in the next days i will prepare a patch.



--
This message was sent by Atlassian JIRA
(v6.2#6252)