Hi K

One of the simplest example of custom job started in a background
thread that needs acces to a usable XWikiContext/XWiii is probably
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-solr/xwiki-platform-search-solr-api/src/main/java/org/xwiki/search/solr/internal/DefaultSolrIndexer.java#L542.

To summarize:
* you annotate your job component
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) to
make it unique get call to getInstance()
* org.xwiki.context.concurrent.ExecutionContextRunnable wrapper is
taking care or initializing an ExecutionContext for that thread for
any Runnable
* you access the current XWikiContext where you need it ny injecting
the XWikiContext Provider

On Thu, Dec 12, 2013 at 3:35 PM, Lukáš Raška <[email protected]> wrote:
> Hi,
> as discussed on IRC, I have trouble creating multiple simultaneous tasks
> from inside component.
>
> Creating new thread results in malformed context, which can result in
> XWikiException.
> This could probably be avoided using Jobs, but nobody seems to know how
> exactly.
>
> As of 5.1, it should be able to create custom jobs by extending
> AbstractJob.
> But how to get context inside that job? Could I use Provider in such way as
> in ScriptWikiStreamConverterJob? (Multitaskness should be achieved with
> InstantiationStrategy)
>
> About what I need to achieve - component creating API for "videolibrary"
> extension (converting video attachment in certaing page to web-playable
> format using libav). Since it should be safe to use, attachment is
> immediately copied to specified temp folder (filesystem) after uploading.
> Old attachment is deleted to ensure we didn't convert same file twice
> (there is no callback with filenames for html5 fileupload widget). After
> this, video will be converted to specified format and attached to different
> page (using InputStream?).
>
> Is this idea safe to use? (or am I missing another possible problem?)
>
>
> Thanks for replies
>
> --
> Best Regards
> Lukas Raska
> _______________________________________________
> devs mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/devs



-- 
Thomas Mortagne
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to