You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Edouard sur edouardmercier.fr" <ed...@edouardmercier.fr> on 2008/10/07 09:24:58 UTC

How to access an ASO in a non-servlet thread

Hi everyone.

I'm currently facing the following problem: my T5 (0.15) web
application receive notifications in a dedicated non servlet thread
inside some of my Tapestry components, which have an
ApplicationStateObject attribute. I would like to update the state of
the ASO, but the problem is that the thread that triggers some
callback in my Tapestry component cannot thus access the AOS (since I
guess resort to ThreadLocal attributes inside the IoC). I can bind the
dedicated notification thread to the servlet thread that created it.

Is there a way in Tapestry to work this around, please?

Thank you. Cheers, Édouard

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


Re: How to access an ASO in a non-servlet thread

Posted by Ulrich Stärk <ul...@spielviel.de>.
Am Di, 7.10.2008, 10:38, schrieb Edouard sur edouardmercier.fr:
> Thank you Uli.
>
> I had already taken a look at the two pointers you have provided,
> without really understanding them: I'm a bit lost on how to start
> with. I've understood that I must create a service and declare it
> inside the AppModule class. I've seen that I should declare an
> interface for such a service, and of course an implementation. I've
> seen that the "PerthreadManager" instance seems to be injected into
> the service implementation.
>
> But:
>
>  - I do not understand the exact purpose of this "PerthreadManager"
> class (since we only use its "cleanup()" method)

The PerthreadManager is used for storing per-thread data. You can put()
and get() data from it and when you call cleanup(), that data is
discarded. See here
http://tapestry.apache.org/tapestry5/apidocs/index.html?org/apache/tapestry5/corelib/components/Select.html
for the API docs.

>  - I do not know how to declare the service in the IoC (is that like
> any regular service in the "bind()" method ?)

Yes. Alternatively you can write a public static YourService
buildYourService(...) method and instantiate it there. See
http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html for
details.

>
> I must also indicate that each client servlet will create its own
> notification thread, and I am afraid that a central service will not
> help...

The above mentioned URL also provides documentation about service scopes.
One scope is the perthread scope, creating an instance of your service for
every thread (i.e. every request).

Cheers,

Uli


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


Re: How to access an ASO in a non-servlet thread

Posted by "Edouard sur edouardmercier.fr" <ed...@edouardmercier.fr>.
Thank you Uli.

I had already taken a look at the two pointers you have provided,
without really understanding them: I'm a bit lost on how to start
with. I've understood that I must create a service and declare it
inside the AppModule class. I've seen that I should declare an
interface for such a service, and of course an implementation. I've
seen that the "PerthreadManager" instance seems to be injected into
the service implementation.

But:

 - I do not understand the exact purpose of this "PerthreadManager"
class (since we only use its "cleanup()" method)
 - I do not know how to declare the service in the IoC (is that like
any regular service in the "bind()" method ?)

I must also indicate that each client servlet will create its own
notification thread, and I am afraid that a central service will not
help...

Thank you for your help.
Édouard

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


Re: How to access an ASO in a non-servlet thread

Posted by Ulrich Stärk <ul...@spielviel.de>.
You can build a Tapestry ioc service around your notification receiver
thread which manages the thread and exposes any notification received.
This service can then be injected into your pages and components and can
be queried for any received notifications.

See http://wiki.apache.org/tapestry/Tapestry5HowToRunTaskInThread and
http://wiki.apache.org/tapestry/Tapestry5HowToWorkQueue for examples.

HTH,

Uli

Am Di, 7.10.2008, 09:24, schrieb Edouard sur edouardmercier.fr:
> Hi everyone.
>
> I'm currently facing the following problem: my T5 (0.15) web
> application receive notifications in a dedicated non servlet thread
> inside some of my Tapestry components, which have an
> ApplicationStateObject attribute. I would like to update the state of
> the ASO, but the problem is that the thread that triggers some
> callback in my Tapestry component cannot thus access the AOS (since I
> guess resort to ThreadLocal attributes inside the IoC). I can bind the
> dedicated notification thread to the servlet thread that created it.
>
> Is there a way in Tapestry to work this around, please?
>
> Thank you. Cheers, Édouard
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



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