Hi Vincent,

I think it might help if you give us a quick overview of what happens with
the XWikiContext inside a thread in XWiki (since there was also a question
regarding this on the users list [1]). That might lead to the current need
to initialize the execution context and to the improvement you are
proposing.

I would be curious of how does one get the component manager from a thread
(using annotations in the [anonymous or not] thread class?) and why can`t
you just use the component manager to get an already initialized execution
context at runtime, inside the thread's run() method. Of course, as stated
in the first phrase of this mail, I`m also curious of what would be the
state of an XWikiContext inside a thread (what are the values for the
context document, user, database, etc).

Thanks,
Eduard

----------
[1] http://xwiki.markmail.org/thread/ortxgpg53l5vjzof

On Sun, Mar 18, 2012 at 2:37 PM, Vincent Massol <[email protected]> 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
>
> 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
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/devs
>
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to