Java Doc for ExecuteAndWaitInterceptor.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » interceptor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » webwork 2.2.6 » com.opensymphony.webwork.interceptor 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor

ExecuteAndWaitInterceptor
public class ExecuteAndWaitInterceptor implements Interceptor(Code)
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.
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 seperate thread, you can't use ActionContext because it is a ThreadLocal. This means if you need to access, for example, session data, you need to implement SessionAware rather than calling ActionContext.getSesion().

The thread kicked off by this interceptor will be named in the form actionNameBrackgroundProcess. For example, the search action would run as a thread named searchBackgroundProcess.

Interceptor 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.

Extending the interceptor:

If you wish to make special preparations before and/or after the invocation of the background thread, you can extend the BackgroundProcess class and implement the beforeInvocation() and afterInvocation() methods. This may be useful for obtaining and releasing resources that the background process will need to execute successfully. To use your background process extension, extend ExecuteAndWaitInterceptor and implement the getNewBackgroundProcess() method.

Example code:

 
 <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>
 

author:
   Pat Lightbody
author:
   Rainer Hermanns
author:
   Claus Ibsen


Field Summary
final public static  StringKEY
    
final public static  StringWAIT
    
protected  intdelay
    
protected  intdelaySleepInterval
    


Method Summary
public  voiddestroy()
    
protected  BackgroundProcessgetNewBackgroundProcess(String name, ActionInvocation actionInvocation, int threadPriority)
    
public  voidinit()
    
public  Stringintercept(ActionInvocation actionInvocation)
    
protected  voidperformInitialDelay(BackgroundProcess bp)
     Performs the initial delay.
public  voidsetDelay(int delay)
     Sets the initial delay in millis (msec).
Parameters:
  delay - in millis.
public  voidsetDelaySleepInterval(int delaySleepInterval)
     Sets the sleep interval in millis (msec) when performing the initial delay.
public  voidsetThreadPriority(int threadPriority)
     Sets the thread priority of the background process.

Field Detail
KEY
final public static String KEY(Code)



WAIT
final public static String WAIT(Code)



delay
protected int delay(Code)



delaySleepInterval
protected int delaySleepInterval(Code)





Method Detail
destroy
public void destroy()(Code)



getNewBackgroundProcess
protected BackgroundProcess getNewBackgroundProcess(String name, ActionInvocation actionInvocation, int threadPriority)(Code)



init
public void init()(Code)



intercept
public String intercept(ActionInvocation actionInvocation) throws Exception(Code)



performInitialDelay
protected void performInitialDelay(BackgroundProcess bp) throws InterruptedException(Code)
Performs the initial delay.

When this interceptor is executed for the first time this methods handles any provided initial delay. An initial delay is a time in miliseconds we let the server wait before we continue.
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.
Parameters:
  bp - the background process
throws:
  InterruptedException - is thrown by Thread.sleep




setDelay
public void setDelay(int delay)(Code)
Sets the initial delay in millis (msec).
Parameters:
  delay - in millis. (0 for not used)



setDelaySleepInterval
public void setDelaySleepInterval(int delaySleepInterval)(Code)
Sets the sleep interval in millis (msec) when performing the initial delay.
Parameters:
  delaySleepInterval - in millis (0 for not used)



setThreadPriority
public void setThreadPriority(int threadPriority)(Code)
Sets the thread priority of the background process.
Parameters:
  threadPriority - the priority from Thread.XXX



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.