You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Burak Doğruöz <ze...@gmail.com> on 2008/07/21 15:30:48 UTC

Execute and wait interceptor and calling an action more than once

Hi,
Our application lets user to run 2 (or more) copies of same action at the
same time (possibly with different parameters) in a frameset.

In execute and wait interceptor documentation (
http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html), it
says that execute and wait interceptor works on a per-session basis and the
same action name cannot be run more than once at a time in a given session.
So how can i extend this interceptor so i can call same action more than
once at the same time?

Is it possible to trigger an action with a name template? For example, i
call myAction1, myAction2 simultaneously which all point to myAction but
stored as separately for execute and wait interceptor.

Thanks.

Re: Execute and wait interceptor and calling an action more than once

Posted by Burak Doğruöz <ze...@gmail.com>.
So, how to override this ExecAndWiatInterceptor behaviour? Is it possible to
map by some key other than action name?

If we use wildcards while defining action mapping, can we bypass this
constraint? This way we can call myAction1, myAction2 and myActionRandomN
which trigger myAction.action. Does ExecAndWaitInterceptor store and return
these separately?

Thanks.
2008/7/21 Jeromy Evans

> No, all S2 action invocations are in a separate thread (one thread per
> request).
>
> Only the ExecAndWaitInterceptor applies constraints because of the way it
> waits for a response.
>
>

Re: Execute and wait interceptor and calling an action more than once

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Burak Doğruöz wrote:
> Thanks for your response,
>
> I think, even with an ajax approach, concurrent requests for same action
> would result in unexpected output as these actions are stored by same action
> name at background. So in fact this is not a presentation constraint but a
> processing constraint. We can neither prevent concurrent submits nor make
> them wait for another to finish. They need to work parallelly. So i think
> what we need here is a way to store background threads separately possibly
> on per-request basis instead of per-session basis?
>
> Thanks.
>   

No, all S2 action invocations are in a separate thread (one thread per 
request).

Only the ExecAndWaitInterceptor applies constraints because of the way 
it waits for a response.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Execute and wait interceptor and calling an action more than once

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Burak Doğruöz wrote:
> I don't think that it can be done with an ajax approach. With ajax or not,
> concurrent requests for the same action name returns first action's result.
>
> I tried this simple scenario with an action which outputs its query
> parameter. I also added a thread.sleep in execute method to gain extra time
> to call the same action more than once.
>
> When i triggered the same action with different parameters in 2 separate
> browsers, first one redirected to the wait page as expected. At that point i
> triggered the second copy. When they both returned  from wait page, both
> output were first action's parameter.
>
> I think ajax/div approach would show the same behaviour with the above.
>
>   
If  you're using ajax, forget the wait page and redirection paradigm.

One async request maps to one action instance in one thread.  There's no 
interference or coupling between action instances at all in S2 unless 
you introduce the coupling yourself
(or use the exec&wait interceptor).

The "waiting page" would instead be a client-side controlled indicator 
displayed while waiting for the async response. It's a common pattern 
intended for exactly what you're trying to do when javascript is available.





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Execute and wait interceptor and calling an action more than once

Posted by Burak Doğruöz <ze...@gmail.com>.
I don't think that it can be done with an ajax approach. With ajax or not,
concurrent requests for the same action name returns first action's result.

I tried this simple scenario with an action which outputs its query
parameter. I also added a thread.sleep in execute method to gain extra time
to call the same action more than once.

When i triggered the same action with different parameters in 2 separate
browsers, first one redirected to the wait page as expected. At that point i
triggered the second copy. When they both returned  from wait page, both
output were first action's parameter.

I think ajax/div approach would show the same behaviour with the above.

However, the wildcard action mapping seems to separate the wait and returns.
when i mapped the action name like myaction* and called myaction1 and
myaction2 at the same time like before, they seem to return with their
respective results. i guess, this can also be used to separate the key.

Thanks for responses.

2008/7/21 Dave Newton <ne...@yahoo.com>:

> --- On Mon, 7/21/08, Burak Doğruöz wrote:
> > The constraint here is about ExecAndWaitInterceptor storing
> > and returning multiple copies of one certain action. This
> > constraint is already in the documentation. We are looking
> > for a turn around.
>
> I was referring to the better solution, Jeremy's Ajax idea.
>
> > there may be no certain result that which browser will show
> > which request.
>
> It may be enough to subclass the interceptor and override
> getBackgroundProcessName(...) (like to use a request parameter to help form
> the session key, etc.) but I haven't tried this.
>
> Dave
>

Re: Execute and wait interceptor and calling an action more than once

Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 7/21/08, Burak Doğruöz wrote:
> The constraint here is about ExecAndWaitInterceptor storing
> and returning multiple copies of one certain action. This
> constraint is already in the documentation. We are looking
> for a turn around.

I was referring to the better solution, Jeremy's Ajax idea.

> there may be no certain result that which browser will show
> which request.

It may be enough to subclass the interceptor and override getBackgroundProcessName(...) (like to use a request parameter to help form the session key, etc.) but I haven't tried this.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Execute and wait interceptor and calling an action more than once

Posted by Burak Doğruöz <ze...@gmail.com>.
The constraint here is about ExecAndWaitInterceptor storing and returning
multiple copies of one certain action. This constraint is already in the
documentation. We are looking for a turn around.

For example if we open 2 browsers (which share the same session) and call
same action (which has ExecAndWaitInterceptor) with different parameters,
there may be no certain result that which browser will show which request.
Thanks
2008/7/21 Dave Newton <ne...@yahoo.com>:

> --- On Mon, 7/21/08, Burak Doğruöz wrote:
> > I think, even with an ajax approach, concurrent requests
> > for same action would result in unexpected output as these
> > actions are stored by same action name at background.
>
> Each request would get its own action instance. The DOM element being
> updated is defined in the tag; if they're different there shouldn't be any
> issues.
>
> Dave
>
>
>

Re: Execute and wait interceptor and calling an action more than once

Posted by Dave Newton <ne...@yahoo.com>.
--- On Mon, 7/21/08, Burak Doğruöz wrote:
> I think, even with an ajax approach, concurrent requests
> for same action would result in unexpected output as these 
> actions are stored by same action name at background.

Each request would get its own action instance. The DOM element being updated is defined in the tag; if they're different there shouldn't be any issues.

Dave


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Execute and wait interceptor and calling an action more than once

Posted by Burak Doğruöz <ze...@gmail.com>.
Thanks for your response,

I think, even with an ajax approach, concurrent requests for same action
would result in unexpected output as these actions are stored by same action
name at background. So in fact this is not a presentation constraint but a
processing constraint. We can neither prevent concurrent submits nor make
them wait for another to finish. They need to work parallelly. So i think
what we need here is a way to store background threads separately possibly
on per-request basis instead of per-session basis?

Thanks.


2008/7/21 Jeromy Evans jeromy.evans@blueskyminds.com.au:
>
>
> This is a good candidate for making asynchronous requests via an ajax
> framework. I would drop the frameset and replace it with a few s:div's
> tiggered by s:submit's from the ajax theme. That's much easier than what
> you're attempting and is what those tags are intended for.
>
> Just my 2c.
>
> regards
> Jeromy Evans
>
>

Re: Execute and wait interceptor and calling an action more than once

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Burak Doğruöz wrote:
> Hi,
> Our application lets user to run 2 (or more) copies of same action at the
> same time (possibly with different parameters) in a frameset.
>
> In execute and wait interceptor documentation (
> http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html), it
> says that execute and wait interceptor works on a per-session basis and the
> same action name cannot be run more than once at a time in a given session.
> So how can i extend this interceptor so i can call same action more than
> once at the same time?
>
>
>   

This is a good candidate for making asynchronous requests via an ajax 
framework. I would drop the frameset and replace it with a few s:div's 
tiggered by s:submit's from the ajax theme. That's much easier than what 
you're attempting and is what those tags are intended for.

Just my 2c.

regards
Jeromy Evans

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Execute and wait interceptor and calling an action more than once

Posted by Giovanni Azua <gi...@imc.nl>.
hi,

I think that actually you can run more than one execAndWait at the time 
for the same Session, the problem though is that you have no guarantee 
on which result will be returned to which browser e.g.

Session 1 - browser 1 - triggers execAndWait => gets result of action 
triggered by Browser 3
Session 1 - browser 2 - triggers execAndWait => gets result of action 
triggered by Browser 1
Session 1 - browser 3 - triggers execAndWait => gets result of action 
triggered by Browser 2

This is a documented limitation of execAndWait and I moved away from it 
also because of this reason.

HTH,
regards,
Giovanni

Burak Doğruöz wrote:
> Hi,
> Our application lets user to run 2 (or more) copies of same action at the
> same time (possibly with different parameters) in a frameset.
>
> In execute and wait interceptor documentation (
> http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html), it
> says that execute and wait interceptor works on a per-session basis and the
> same action name cannot be run more than once at a time in a given session.
> So how can i extend this interceptor so i can call same action more than
> once at the same time?
>
> Is it possible to trigger an action with a name template? For example, i
> call myAction1, myAction2 simultaneously which all point to myAction but
> stored as separately for execute and wait interceptor.
>
> Thanks.
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org