You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Thorsten Schöning <ts...@am-soft.de> on 2020/03/29 13:45:12 UTC

Is it safe to use ComponentRenderer with different apps in the same thread one after another?

Hi all,

I'm using Wicket as some render engine to render mails for reports
consisting of different individual render approaches: plain text only,
HTML only, a combination of both. In the latter case I of course would
like to simply reuse the former approaches, but am not sure if the
used ComponentRenderer does support that.

My individual rendering looks like the following:

> private static  String
>                 forSome(VwrCtx                ctx,
>                         Supplier<VwrHtmlPage> page)
> {
>     try (VwrCtxThreadScoped scopedCtx = new VwrCtxThreadScoped(ctx))
>     {
>         VwrHtmlApp          app         = new VwrHtmlApp();
>         ComponentRenderer   renderer    = new ComponentRenderer(app);
>         CharSequence        retVal      = renderer.renderPage(page);
> 
>         return retVal.toString();
>     }
> }

"renderer.renderPage" is where I would call the above additionally to
provide text- and HTML-only. From my understanding that should be
safe, because ComponentRenderer supports multiple different contexts
for app etc.:

> private <T> T inThreadContext(Supplier<T> supplier)
> {
>     ThreadContext oldContext = ThreadContext.detach();
> 
>     try
>     {
>         ThreadContext.setApplication(application);
> 
>         return supplier.get();
>     }
>     finally
>     {
> 
>         ThreadContext.restore(oldContext);
>     }
> }

As well I really only need to render within one and the same thread
one after another, I'm not resuing apps or contexts between different
threads in parallel. If that would be needed at some point, it would
be dealt with at a higher level rendering using some threadpool.

So, is it safe to render recursively using ComponentRenderer within
one and the same thread? Thanks!

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Is it safe to use ComponentRenderer with different apps in the same thread one after another?

Posted by Sven Meier <sv...@meiers.net>.
Hi Thorsten,

 > As well I really only need to render within one and the same thread
 > one after another,

that should work.

 > is it safe to render recursively using ComponentRenderer within
 > one and the same thread?

I assume you mean 'consecutively'? Yes, see above.

Have fun
Sven


On 29.03.20 15:45, Thorsten Schöning wrote:
> Hi all,
>
> I'm using Wicket as some render engine to render mails for reports
> consisting of different individual render approaches: plain text only,
> HTML only, a combination of both. In the latter case I of course would
> like to simply reuse the former approaches, but am not sure if the
> used ComponentRenderer does support that.
>
> My individual rendering looks like the following:
>
>> private static  String
>>                  forSome(VwrCtx                ctx,
>>                          Supplier<VwrHtmlPage> page)
>> {
>>      try (VwrCtxThreadScoped scopedCtx = new VwrCtxThreadScoped(ctx))
>>      {
>>          VwrHtmlApp          app         = new VwrHtmlApp();
>>          ComponentRenderer   renderer    = new ComponentRenderer(app);
>>          CharSequence        retVal      = renderer.renderPage(page);
>>
>>          return retVal.toString();
>>      }
>> }
> "renderer.renderPage" is where I would call the above additionally to
> provide text- and HTML-only. From my understanding that should be
> safe, because ComponentRenderer supports multiple different contexts
> for app etc.:
>
>> private <T> T inThreadContext(Supplier<T> supplier)
>> {
>>      ThreadContext oldContext = ThreadContext.detach();
>>
>>      try
>>      {
>>          ThreadContext.setApplication(application);
>>
>>          return supplier.get();
>>      }
>>      finally
>>      {
>>
>>          ThreadContext.restore(oldContext);
>>      }
>> }
> As well I really only need to render within one and the same thread
> one after another, I'm not resuing apps or contexts between different
> threads in parallel. If that would be needed at some point, it would
> be dealt with at a higher level rendering using some threadpool.
>
> So, is it safe to render recursively using ComponentRenderer within
> one and the same thread? Thanks!
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org