Hey,
On Fri, May 25, 2018 at 8:56 AM, Michiel Rop <
michi...@bloomreach.com> wrote:
> Hi Kah,
>
> Some more elaboration on Marijan's spot on answer.
>
> The HstRequestContext contains many parameters that are only valid during
> the request. The most important one is the jcr session, that will be used to
> retrieve most of the data of your component, is closed once the request
> completes. If you want to perform any background task, make sure to create (
> and close ) a new session *inside* your background task.
>
> It depends on your requirements, but in general a "Repository-Managed
> Component' or daemon module [1] is better suited to run longer running
> background task. They can be called from a component as well.
This is most likely not what Kah is after, he most likely wants to
make use of parallel hst component preprocessing, see [1]. This is
typically useful when for example one or more component use an
external call to a rest service (or use CRISP). In general, JCR
related code you do not in the prepareBeforeRender phase: Namely, when
using a CompletableFuture, the work in the future is done with another
Thread, and a JCR session is not thread safe. You could use a
different JCR session, but this typically does not really improve your
performance. Instead, in prepareBeforeRender with a CompletableFuture
use things that take long and typically have a large i/o (like doing
an external micro service request over http).
Daemon modules serve a complete different purpose and run in the cms
webapp instead of the site delivery webapp, which is quite unlikely
what Kah is after.
Last thing: when using a CompletableFuture,
RequestContextProvider.get() won't return the HstRequestContext any
more since the RequestContextProvider uses Thread locals. Therefor, in
general, in your CompletableFuture you cannot use code from the HST
that relies on fetching the HstRequestContext via
RequestContextProvider.get().
HTH,
Regards Ard
[1]
https://www.onehippo.org/library/concepts/component-development/parallel-hstcomponent-preprocessing.html
Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
Hippo USA, Inc. 71 Summer Street, 2nd Floor Boston, MA 02110, United
states of America.
US
+1 877 414 4776 (toll free)
Europe
+31(0)20 522 4466
www.onehippo.com