|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor
public class ExecuteAndWaitInterceptor
The ExecuteAndWaitInterceptor is great for running long-lived actions in the background while showing the user a nice progress meter. This also prevents the HTTP request from timing out when the action takes more than 5 or 10 minutes.
Using this interceptor is pretty straight forward. Assuming that you are including webwork-default.xml, this interceptor is already configured but is not part of any of the default stacks. Because of the nature of this interceptor, it must be the last interceptor in the stack. This interceptor works on a per-session basis. That means that the same action name (myLongRunningAction, in the above example) 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. If no "wait" result is found, WebWork will automatically generate a wait result on the fly. This result is written in FreeMarker and cannot run unless FreeMarker is installed. If you don't wish to deploy with FreeMarker, you must provide your own wait result. This is generally a good thing to do anyway, as the default wait page is very plain. 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), you can give the appearance of an automatic progress meter. This interceptor also supports using an initial wait delay. An initial delay is a time in milliseconds we let the server wait before the wait page is shown to the user. During the wait this interceptor will wake every 100 millis 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.Thread.NORM_PRIORITY
.wait
as result code). Default is no initial delay.<action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="completeStack"/> <interceptor-ref name="execAndWait"/> <result name="wait">longRunningAction-wait.jsp</result> <result name="success">longRunningAction-success.jsp</result> </action> <%@ taglib prefix="ww" uri="/webwork" %> <html> <head> <title>Please wait</title> <meta http-equiv="refresh" content="5;url=<ww:url includeParams="all" />"/> </head> <body> Please wait while we process your request. Click <a href="<ww:url includeParams="all" />"></a> if this page does not reload automatically. </body> </html>Example code2: This example will wait 2 second (2000 millis) before the wait page is shown to the user. Therefore if the long process didn't last long anyway the user isn't shown a wait page.
<action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="completeStack"/> <interceptor-ref name="execAndWait"> <param name="delay">2000<param> <interceptor-ref> <result name="wait">longRunningAction-wait.jsp</result> <result name="success">longRunningAction-success.jsp</result> </action>Example code3: This example will wait 1 second (1000 millis) before the wait page is shown to the user. And at every 50 millis this interceptor will check if the background process is done, if so it will return before the 1 second has elapsed, and the user isn't shown a wait page.
<action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="completeStack"/> <interceptor-ref name="execAndWait"> <param name="delay">1000<param> <param name="delaySleepInterval">50<param> <interceptor-ref> <result name="wait">longRunningAction-wait.jsp</result> <result name="success">longRunningAction-success.jsp</result> </action>
Field Summary | |
---|---|
protected int |
delay
|
protected int |
delaySleepInterval
|
static String |
KEY
|
static String |
WAIT
|
Constructor Summary | |
---|---|
ExecuteAndWaitInterceptor()
|
Method Summary | |
---|---|
void |
destroy()
Called to let an interceptor clean up any resources it has allocated. |
protected BackgroundProcess |
getNewBackgroundProcess(String name,
ActionInvocation actionInvocation,
int threadPriority)
|
void |
init()
Called after an interceptor is created, but before any requests are processed using intercept , giving
the Interceptor a chance to initialize any needed resources. |
String |
intercept(ActionInvocation actionInvocation)
Allows the Interceptor to do some processing on the request before and/or after the rest of the processing of the request by the ActionInvocation or to short-circuit the processing and just return a String return code. |
protected void |
performInitialDelay(BackgroundProcess bp)
Performs the initial delay. |
void |
setDelay(int delay)
Sets the initial delay in millis (msec). |
void |
setDelaySleepInterval(int delaySleepInterval)
Sets the sleep interval in millis (msec) when performing the initial delay. |
void |
setThreadPriority(int threadPriority)
Sets the thread priority of the background process. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String KEY
public static final String WAIT
protected int delay
protected int delaySleepInterval
Constructor Detail |
---|
public ExecuteAndWaitInterceptor()
Method Detail |
---|
public void init()
Interceptor
intercept
, giving
the Interceptor a chance to initialize any needed resources.
init
in interface Interceptor
protected BackgroundProcess getNewBackgroundProcess(String name, ActionInvocation actionInvocation, int threadPriority)
public String intercept(ActionInvocation actionInvocation) throws Exception
Interceptor
ActionInvocation
or to short-circuit the processing and just return a String return code.
intercept
in interface Interceptor
ActionInvocation.invoke()
, or from the interceptor itself.
Exception
- any system-level error, as defined in Action.execute()
.public void destroy()
Interceptor
destroy
in interface Interceptor
protected void performInitialDelay(BackgroundProcess bp) throws InterruptedException
bp
- the background process
InterruptedException
- is thrown by Thread.sleeppublic void setThreadPriority(int threadPriority)
threadPriority
- the priority from Thread.XXX
public void setDelay(int delay)
delay
- in millis. (0 for not used)public void setDelaySleepInterval(int delaySleepInterval)
delaySleepInterval
- in millis (0 for not used)
|
WebWork Project Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |