incubator-jspwiki-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Janne Jalkanen <>
Subject Re: JCR integration
Date Mon, 09 Feb 2009 09:12:54 GMT
> Re-reading your e-mail, I *think* I understand the comment you made
> about not wanting to keep a ThreadLocal field in ContentManager that
> keeps a reference to the current Session. But why keep the Session?
> Couldn't a getPage() operation open a new Session, get the page, then
> close the Session and return the page? Then there'd be no reason to
> stash the Session anywhere.

The problem is that the Node keeps a reference to a Session, and the
WikiPage holds a reference to the Node (if it does not, it is
impossible to manipulate the content of the repository through
WikiPage methods, such as get/setAttribute()).

So, if getPage() closes the session, all attempts to use the WikiPage
for anything will fail spectacularly.

> Or alternatively, maybe you (we) guarantee that any time we get a
> Session we have to complete work on the session, then call refresh(),
> before returning. That would mean you could keep ThreadLocals in
> ContentManager. But maybe I'm missing your point about the exception
> cases. Could you explain further?

Guaranteeing calling Session.refresh() means the following pattern:

m_engine = ... // Get engine somehow
   WikiPage p = m_engine.getPage(...)
   // Do something
   // This must be done here, or exceptions will go upwards and
   // one might end up with unpurged data in the Session.
   m_engine.getContentManager().refresh(); // Calls Session.refresh()

So in the end this pattern is *exactly* the same as the pattern above,
with the exception that this does not explicitly state the start of
the Session, and leaves the lifecycle muddy.  We can't call
refresh in our WikiFilter because that does not work for embedders.

Note that for the most part, the pattern I suggested will only affect
WikiFilter and WikiContextFactory, since those are the ones who get
WikiEngine. Most of our APIs get a WikiContext, and for plugin writers
*nothing* would change (because they did not acquire a WikiEngine,
they just used WikiContext.getEngine()).


View raw message