You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@deltaspike.apache.org by "l.penet@senat.fr" <l....@senat.fr> on 2016/07/21 17:16:46 UTC

Advice on accessing @RequestScoped bean in service thread

Hi.

I am looking for an advice on how to acces a request scoped bean in a 
service thread. My current need is in a web socket service thread, but 
it could be any background thread.

The bean I need to access is a data access bean, which will itself 
request injection of an entity manager to perform various operations. It 
does in fact nothing related to the HTTP session, but I want to be sure 
that every requests gets a clean bean.

How do you recommend to do that ? If I boldly try to une 
BeanProvider.getContextualInstance(), it does not work as there is, of 
course, no request scope. Should I start a pseudo request scope ? Is 
there an annotation for that ?

Thanks in advance,

Ludovic


|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: Advice on accessing @RequestScoped bean in service thread

Posted by "l.penet@senat.fr" <l....@senat.fr>.
On 21/07/2016 20:54, John D. Ament wrote:
> This sounds like something useful and reusable, would it help if we
> provided websockets support OOTB?
Support for easily getting a context in any async service, definitely.
Having an annotation that we could set on a method or even a class would 
be great.


websockets support would certainly be great. I, however, prefer to use 
atmosphere ( https://github.com/Atmosphere/ ) as it
also provides many goodies, such as fallback support, its broadcaster 
mechanism, heartbeat, scaling tools and so on.

So, a generic support would be great.

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: Advice on accessing @RequestScoped bean in service thread

Posted by "John D. Ament" <jo...@apache.org>.
This sounds like something useful and reusable, would it help if we
provided websockets support OOTB?

On Jul 21, 2016 14:11, "Ludovic Pénet" <l....@senat.fr> wrote:

> Ok, found it
>
> On https://deltaspike.apache.org/documentation/container-control.html
>
> Read "Attach a RequestContext to a New Thread in EE".
>
> I think I will write an interceptor to make it even easier to use.
>
> Thanks !
>
> Le 21 juillet 2016 19:35:44 GMT+02:00, "l.penet@senat.fr" <
> l.penet@senat.fr> a écrit :
> >On 21/07/2016 19:20, John D. Ament wrote:
> >> Ludovic,
> >>
> >> Are you using context control to start a request context on the
> >websockets
> >> thread?
> >No.
> >
> >But if that's your recommendation, I can do that.
> >
> >Where do I find it in the doc ?
> >
> >Thank you !
> >
> >Ludovic
> >
> >|
> >| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
> >|
>
> --
> Envoyé de mon appareil Android avec K-9 Mail. Veuillez excuser ma brièveté.

Re: Advice on accessing @RequestScoped bean in service thread

Posted by Ludovic Pénet <l....@senat.fr>.
Ok, found it 

On https://deltaspike.apache.org/documentation/container-control.html

Read "Attach a RequestContext to a New Thread in EE".

I think I will write an interceptor to make it even easier to use.

Thanks !

Le 21 juillet 2016 19:35:44 GMT+02:00, "l.penet@senat.fr" <l....@senat.fr> a �crit :
>On 21/07/2016 19:20, John D. Ament wrote:
>> Ludovic,
>>
>> Are you using context control to start a request context on the
>websockets
>> thread?
>No.
>
>But if that's your recommendation, I can do that.
>
>Where do I find it in the doc ?
>
>Thank you !
>
>Ludovic
>
>|
>| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
>|

-- 
Envoy� de mon appareil Android avec K-9 Mail. Veuillez excuser ma bri�vet�.

Re: Advice on accessing @RequestScoped bean in service thread

Posted by "l.penet@senat.fr" <l....@senat.fr>.
On 21/07/2016 19:20, John D. Ament wrote:
> Ludovic,
>
> Are you using context control to start a request context on the websockets
> thread?
No.

But if that's your recommendation, I can do that.

Where do I find it in the doc ?

Thank you !

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: Advice on accessing @RequestScoped bean in service thread

Posted by "John D. Ament" <jo...@gmail.com>.
Ludovic,

Are you using context control to start a request context on the websockets
thread?

On Jul 21, 2016 13:16, "l.penet@senat.fr" <l....@senat.fr> wrote:

> Hi.
>
> I am looking for an advice on how to acces a request scoped bean in a
> service thread. My current need is in a web socket service thread, but it
> could be any background thread.
>
> The bean I need to access is a data access bean, which will itself request
> injection of an entity manager to perform various operations. It does in
> fact nothing related to the HTTP session, but I want to be sure that every
> requests gets a clean bean.
>
> How do you recommend to do that ? If I boldly try to une
> BeanProvider.getContextualInstance(), it does not work as there is, of
> course, no request scope. Should I start a pseudo request scope ? Is there
> an annotation for that ?
>
> Thanks in advance,
>
> Ludovic
>
>
> |
> | AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
> |
>
>