Hi,

On Tue, Jan 7, 2014 at 11:50 AM, Bertrand Delacretaz
<[email protected]> wrote:
> Hi,
>
> On Tuesday, January 7, 2014, Justin Edelson wrote:
>
>> ...What I'm in the process of doing is
>> changing the OSGiServiceInjector so that if the adaptable is a
>> request, it uses SlingScriptHelper intead of the bundle context so at
>> least the references are released if you use a request as the
>> adaptable. But I don't see a good way to handle this otherwise. Any
>> ideas?...
>
> IIUC the general problem is making sure things are cleaned up when Sling is
> done processing the current request - we might design a specific mechanism
> for that. Maybe an object in the request attributes to which you can add
> Callables that are executed at the end of a request?

In a request context, this already works - SlingScriptHelper keeps
track of the OSGi services it obtains and calls unget on them when the
request is finished. The problem is in a non-request context, like a
scheduled job, where there is no obvious (at least not obvious to me)
transaction boundary.

The only thing I can think of is to add a special "Disposer" injection
which then a model object needs to call via some method, i.e.

@Model(adaptables = Resource.class)
public class MyModel {

@Inject
private Disposer disposer

public void dispose() {
   disposer.dispose()
}

}

So a client would do:
MyModel model = resource.adaptTo(MyModel.class)
// do some work with model
model.dispose();


Justin

>
> Unless we have such a general mechanism already, but I don't think so.
>
> -Bertrand

Reply via email to