+1
On Sun, Mar 18, 2012 at 1:37 PM, Vincent Massol <vincent(a)massol.net> wrote:
Hi devs,
Whenever we create Threads we need to initialize an Execution Context. Here's the
code that we need to write in run():
ExecutionContext context = execution.getContext();
if (context == null) {
// Create a clean Execution Context
context = new ExecutionContext();
try {
executionContextManager.initialize(context);
} catch (ExecutionContextException e) {
throw new RuntimeException("Failed to initialize IRC Bot's
execution context", e);
}
// Bridge with old XWiki Context, required for old code.
XWikiContext xwikiContext = stubContextProvider.createStubContext();
context.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xwikiContext);
execution.pushContext(context);
}
I'm thus proposing to do this:
* Create a xwiki-platform-container-deamon module
* Introduce a ContextualizedThread which extends Thread and which adds an
initializeExecutionContext() method
Thus when we need to create threads we extend ContextualizedThread and in our run()
method we start by calling initializeExecutionContext().
Implementation detail:
* This new module will depend on xwiki-platform-oldcore since it needs to use
XWikiStubContextProvider
* This means that this new module cannot be used from within xwiki-platform-oldcore but
that should be ok since I don't see why we would need to create threads in there
We do create threads in there actually (stats for example and probably
others) but IMO that give another excuse to extract or rewrite more
things.
Rationale:
* The reason I need this is because I've recoded the code snippet I've put above
in the new IRC Bot application and now I'm finding that the Link Checker feature
(which uses a Thread) is also missing this and I need to add it there too. Thus we really
need to put this code in a common place, hence the suggestion for the new deamon module.
Here's my +1
Thanks
-Vincent
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Thomas Mortagne