[ 
https://issues.apache.org/jira/browse/WW-4874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16223520#comment-16223520
 ] 

ASF GitHub Bot commented on WW-4874:
------------------------------------

yasserzamani opened a new pull request #179: WW-4874 Introduces Servlet3 plugin 
(adds support for async methods)
URL: https://github.com/apache/struts/pull/179
 
 
   > Tested with high concurrent requests using JMeter (a simple async action 
which returns a json result after 40 seconds).
   # Simple usage
   ## Action
   ```java
   public class AsyncAction {
       public Callable<String> execute() throws InterruptedException {
           return new Callable<String>() {
               @Override
               public String call() throws Exception {
                   waitForEvent();
                   return "success";
               }
           });
       }
   
       private void waitForEvent() throws InterruptedException {
           Thread.sleep(40000);
       }
   }
   ```
   ## struts.xml
   ```xml
   <action name="async" 
class="me.zamani.yasser.ww_convention.actions.AsyncAction">
        <result name="success" type="json" />
   </action>
   ```
   ## web.xml
   ```xml
       <servlet>
           <servlet-name>appServlet</servlet-name>
           
<servlet-class>org.apache.struts2.dispatcher.servlet.StrutsServlet</servlet-class>
           <load-on-startup>1</load-on-startup>
           <async-supported>true</async-supported>
       </servlet>
   
       <servlet-mapping>
           <servlet-name>appServlet</servlet-name>
           <url-pattern>/</url-pattern>
       </servlet-mapping>
   ```
   # Customize timeout
   ## Action
   ```java
   public class AsyncAction {
       public Callable<String> execute() throws InterruptedException {
           return new 
org.apache.struts2.servlet3.async.AsyncAction(60000/*timeout*/,
    new Callable<String>() {
               @Override
               public String call() throws Exception {
                   waitForEvent();
                   return "success";
               }
           });
       }
   
       private void waitForEvent() throws InterruptedException {
           Thread.sleep(40000);
       }
   }
   ```
   # Serializing multiple async tasks ❗️ 😮 
   ## Action
   ```java
   public class AsyncAction {
       public Callable<String> execute() throws InterruptedException {
           return new Callable<String>() {
               @Override
               public String call() throws Exception {
                   waitForEvent1();
           return new Callable<String>() {
               @Override
               public String call() throws Exception {
                   waitForEvent2();
                   return "success";
               }
           });
               }
           });
       }
   
       private void waitForEvent1() throws InterruptedException {
           Thread.sleep(40000);
       }
   
       private void waitForEvent2() throws InterruptedException {
           Thread.sleep(40000);
       }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Asynchronous action method
> --------------------------
>
>                 Key: WW-4874
>                 URL: https://issues.apache.org/jira/browse/WW-4874
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Core Actions, Dispatch Filter
>            Reporter: Yasser Zamani
>              Labels: action, asynchronous
>             Fix For: 2.5.x
>
>   Original Estimate: 1,344h
>  Remaining Estimate: 1,344h
>
> User will be able to return {{java.util.concurrent.Callable<String>}} in 
> their actions. Struts when sees such result, runs {{resultCode = 
> result.call();}} in it's own managed thread pool but exits from servlet's 
> main thread with a null result, i.e. gives back main thread to container and 
> leaves response open for concurrent processing. When {{resultCode = 
> result.call();}} returned, Struts calls 
> {{javax.servlet.AsyncContext.dispatch()}} and {{resumes request processing}} 
> within a container's thread servlet to generate the appropriate result for 
> user according to {{resultCode}}.
> This adds better support for SLS (Short request processing, Long action 
> execution, Short response processing) via Servlet 3's Async API.
> Support of other cases like SSL (e.g. a download server) or LLL(e.g. a video 
> converter server) is still open.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to