public class ExecuteAndWaitInterceptor extends MethodFilterInterceptor
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="s" uri="/struts" %> <html> <head> <title>Please wait</title> <meta http-equiv="refresh" content="5;url=<s:url includeParams="all" />"/> </head> <body> Please wait while we process your request. Click <a href="<s: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>
Modifier and Type | Field and Description |
---|---|
protected int |
delay |
protected int |
delaySleepInterval |
protected boolean |
executeAfterValidationPass |
static String |
KEY |
static String |
WAIT |
excludeMethods, includeMethods, log
Constructor and Description |
---|
ExecuteAndWaitInterceptor() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
protected String |
doIntercept(ActionInvocation actionInvocation) |
protected String |
getBackgroundProcessName(ActionProxy proxy)
Returns the name to associate the background process.
|
protected BackgroundProcess |
getNewBackgroundProcess(String name,
ActionInvocation actionInvocation,
int threadPriority)
Creates a new background process
|
void |
init() |
protected void |
performInitialDelay(BackgroundProcess bp)
Performs the initial delay.
|
void |
setContainer(Container container) |
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 |
setExecuteAfterValidationPass(boolean executeAfterValidationPass)
Whether to start the background process after the second pass (first being validation)
or not
|
void |
setThreadPriority(int threadPriority)
Sets the thread priority of the background process.
|
applyInterceptor, getExcludeMethodsSet, getIncludeMethodsSet, intercept, setExcludeMethods, setIncludeMethods
public static final String KEY
public static final String WAIT
protected int delay
protected int delaySleepInterval
protected boolean executeAfterValidationPass
public void setContainer(Container container)
public void init()
init
in interface Interceptor
init
in class AbstractInterceptor
protected BackgroundProcess getNewBackgroundProcess(String name, ActionInvocation actionInvocation, int threadPriority)
name
- The process nameactionInvocation
- The action invocationthreadPriority
- The thread priorityprotected String getBackgroundProcessName(ActionProxy proxy)
protected String doIntercept(ActionInvocation actionInvocation) throws Exception
doIntercept
in class MethodFilterInterceptor
Exception
public void destroy()
destroy
in interface Interceptor
destroy
in class AbstractInterceptor
protected void performInitialDelay(BackgroundProcess bp) throws InterruptedException
bp
- the background processInterruptedException
- 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)public void setExecuteAfterValidationPass(boolean executeAfterValidationPass)
executeAfterValidationPass
- the executeAfterValidationPass to setCopyright © 2000-2014 Apache Software Foundation. All Rights Reserved.