You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Dimitar Dimitrov <dd...@consult.bg> on 2013/05/15 10:14:53 UTC
Sling get property value by Scheduler based job
Hello everyone.
I have a problem with getting the property value when I use a Quartz
Scheduler job. The problem is that the session which is used to put the
job into the scheduler, becomes closed when the jobs tries to fire the
event.
So the code is quite simple.
Node node;
String propValue = node.getProperty("result").getString();
So I have an instance of node, but when I try to get his property value
"result" I stuck with the exception: "javax.jcr.RepositoryException:
this session has been closed".
This is happens only when I use the job scheduler embedded into the
Sling. I suppose that the job class did not preserve the session
persistence when the job fires, because it is closed already when I put
the job into the repository. If there any reasonable option for action
from this point or I need to do some form persistence of the session
until its launch.
Thanks in advance.
Dimitar
Re: Sling get property value by Scheduler based job
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,
On Wed, May 15, 2013 at 10:14 AM, Dimitar Dimitrov <dd...@consult.bg> wrote:
>... I have a problem with getting the property value when I use a Quartz
> Scheduler job. The problem is that the session which is used to put the job
> into the scheduler, becomes closed when the jobs tries to fire the event...
That's by design, JCR sessions that Sling opens during request
processing are closed once done processing the request.
If you need a Session and you don't have a Request (as in job
processing), you'll need to open it yourself.
JCR sessions are cheap so it's ok to open one just to do a few things
and close it immediately. Or you can have a long-lived Session in the
service that processes your jobs, but note that Sessions should not be
shared between threads.
You can use Session. impersonate(...) to transform a session that you
got with loginAdministrative into one that doesn't have admin rights.
-Bertrand