Top Banner
Apex T. G. India Pvt. Ltd ExecuteAndWait Interceptor Struts Framework Introduction
13

ExecuteAndWait Interceptor

Aug 06, 2015

Download

Technology

Seo Trainee
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ExecuteAndWait Interceptor

Apex T. G. India Pvt. Ltd

ExecuteAndWait Interceptor

Struts Framework

Introduction

Page 2: ExecuteAndWait Interceptor

1

execAndWait

The ExecuteAndWaitInterceptor is used for running long-

lived actions in the background while showing the user a

progress meter(loader image using JavaScript) .

This also prevents the HTTP request from timing out when

the action takes more than 5 or 10 minutes.

Page 3: ExecuteAndWait Interceptor

1

execAndWait

Using this interceptor is pretty straight forward.

Assuming that you are including struts-default.xml, and this

interceptor is already configured but is not part of any of the

default stacks then it wont work.

Because of the nature of this interceptor, it must be

the last interceptor in the stack.

Page 4: ExecuteAndWait Interceptor

1

execAndWait This interceptor works on a per-session basis.

It means, same action name ( DemoAction.class ) cannot be

run more than once at a time in a given session. On the

initial request or any subsequent requests (before the action

has completed), the wait result will be returned. 

The wait result is responsible for issuing a subsequent

request back to the action, giving the effect of a self-updating

progress meter.

Page 5: ExecuteAndWait Interceptor

1

execAndWait If no "wait" result is found, Struts will automatically

generate a wait result on the fly.

But this result is written in FreeMarker and cannot run

unless FreeMarker is installed.

If you don't want to use it with FreeMarker then must

provide a wait page as a result.

Page 6: ExecuteAndWait Interceptor

1

execAndWait Whenever the wait result is returned, the action that is

currently running in the background will be placed on top of

the stack.

This allows you to display progress data, such as a count, in

the wait page. By making the wait page automatically reload

the request to the action (which will be short-circuited by

the interceptor), can give the appearance of an automatic

progress meter.

Page 7: ExecuteAndWait Interceptor

1

execAndWait Whenever the wait result is returned, the action that is

currently running in the background will be placed on top of

the stack.

This allows you to display progress data, such as a count, in

the wait page. By making the wait page automatically reload

the request to the action (which will be short-circuited by

the interceptor), can give the appearance of an automatic

progress meter.

Page 8: ExecuteAndWait Interceptor

1

execAndWait This interceptor also supports using an initial wait delay. An

initial delay is a time in milliseconds let the server wait

before the wait page is shown to the user.

During the wait this interceptor will wake every 100 milii

second to check if the background process is done

premature, thus if the job for some reason doesn't take to

long the wait page is not shown to the user. 

Page 9: ExecuteAndWait Interceptor

1

execAndWait This is useful for e.g. search actions that have a wide span of

execution time. Using a delay time of 2000 millis we ensure

the user is presented fast search results immediately and for

the slow results a wait page is used.

Important: Because the action will be running in a separate

thread, We can't use ActionContext because it is a

ThreadLocal.

Page 10: ExecuteAndWait Interceptor

1

execAndWait

The thread kicked off by this interceptor will be named in

the form actionNameBackgroundProcess.

This means if we need to access session data, we need to

implement SessionAware rather than calling

ActionContext.getSession().

Page 11: ExecuteAndWait Interceptor

1

execAndWait Parameters:threadPriority (optional) - the priority to

assign the thread. Default is Thread.NORM_PRIORITY.

delay (optional) - an initial delay in millis to wait before the

wait page is shown (returning wait as result code). Default is

no initial delay.

delaySleepInterval (optional) - only used with delay. Used

for waking up at certain intervals to check if the background

process is already done. Default is 100 millis.

Page 12: ExecuteAndWait Interceptor

1

execAndWait

<action name=“abc" class="com.abc.DemoAction

<interceptor-ref name="execAndWait"/>

<result name="wait">wait.jsp</result>

<result name="success">success.jsp</result>

</action>

Page 13: ExecuteAndWait Interceptor

Thanks

facebook.com/apex.tgi

twitter.com/ApextgiNoida

pinterest.com/apextgi

Stay Connected with us for more chapters on JAVA