Updated Branches:
  refs/heads/wicket-1.5.x 0fdae2e8e -> 1fe42f0f5

WICKET-4665 Add a new AjaxChannel that discards any Ajax requests if there is a 
running request in the same channel


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/1fe42f0f
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/1fe42f0f
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/1fe42f0f

Branch: refs/heads/wicket-1.5.x
Commit: 1fe42f0f59f460979751f5c43e5f293011e5cb72
Parents: 0fdae2e
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Mon Jul 23 16:10:22 2012 +0300
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Mon Jul 23 16:10:22 2012 +0300

----------------------------------------------------------------------
 .../java/org/apache/wicket/ajax/AjaxChannel.java   |   40 ++++++++++++---
 .../java/org/apache/wicket/ajax/wicket-ajax.js     |   15 ++++--
 2 files changed, 42 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/1fe42f0f/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java 
b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java
index a22b81d..7535af1 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxChannel.java
@@ -20,15 +20,16 @@ import org.apache.wicket.IClusterable;
 import org.apache.wicket.util.lang.Args;
 
 /**
- * A Channel that used to process Ajax requests.
- * 
+ * A Channel used to define how Ajax requests are processed at the client side.
+ *
  * Channels are either:
  * <ul>
  * <li>queueing - Ajax requests are kept in a Queue at the client side and 
processed one at a time.
  * Default.</li>
- * <li>dropping - only the last Ajax request is processed, the others are 
discarded</li>
+ * <li>dropping - only the last Ajax request is processed, all previously 
scheduled requests are discarded</li>
+ * <li>active - discards any Ajax requests if there is a running Ajax request 
on the same channel</li>
  * </ul>
- * 
+ *
  * @author Martin Dilger
  */
 public class AjaxChannel implements IClusterable
@@ -48,7 +49,12 @@ public class AjaxChannel implements IClusterable
                /**
                 * dropping - only the last Ajax request is processed, the 
others are discarded
                 */
-               DROP;
+               DROP,
+
+               /**
+                * the ajax call will discarded if there is an active/running 
request on the same channel
+                */
+               ACTIVE
        }
 
        private final String name;
@@ -110,8 +116,26 @@ public class AjaxChannel implements IClusterable
        @Override
        public String toString()
        {
-               // 's' comes from 'stack', but it really acts as a queue.
-               // TODO Wicket 1.6 - consider renaming it to 'q'
-               return String.format("%s|%s", name, type == Type.QUEUE ? "s" : 
"d");
+               return String.format("%s|%s", name, getShortType(type));
+       }
+
+       private String getShortType(Type t)
+       {
+               String shortType;
+               switch (t)
+               {
+                       case DROP:
+                               shortType = "d";
+                               break;
+                       case ACTIVE:
+                               shortType = "a";
+                               break;
+                       case QUEUE:
+                       default:
+                               // 's' comes from 'stack', but it really acts 
as a queue.
+                               // TODO Wicket 1.6 - consider renaming it to 'q'
+                               shortType = "s";
+               }
+               return shortType;
        }
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/1fe42f0f/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js 
b/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
index ca26c7e..98661c7 100644
--- a/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
+++ b/wicket-core/src/main/java/org/apache/wicket/ajax/wicket-ajax.js
@@ -649,7 +649,7 @@ Wicket.DOM.containsElement = function(element) {
 Wicket.Channel = Wicket.Class.create();
 Wicket.Channel.prototype = {
        initialize: function(name) {
-               var res = name.match(/^([^|]+)\|(d|s)$/)
+               var res = name.match(/^([^|]+)\|(d|s|a)$/)
                if (res == null) {
                        this.name = '';
                        this.type ='s'; // default to stack
@@ -672,15 +672,20 @@ Wicket.Channel.prototype = {
                                Wicket.Log.error("An error occurred while 
executing Ajax request:" + exception);
                        }
                } else {
-                       Wicket.Log.info("Channel busy - postponing...");
-                       if (this.type == 's') { // stack 
+                       var busyChannel = "Channel '"+ this.name+"' is busy";
+                       if (this.type == 's') { // stack
+                               Wicket.Log.info(busyChannel + " - scheduling 
the callback to be executed when the previous request finish.");
                                this.callbacks.push(callback);
                        }
-                       else { // drop
+                       else if (this.type === 'd') { // drop
+                               Wicket.Log.info(busyChannel + " - dropping all 
previous scheduled callbacks and scheduled a new one to be executed when the 
current request finish.");
                                this.callbacks = [];
                                this.callbacks[0] = callback;
                        }
-                       return null;                            
+                       else if (this.type === 'a') { // active
+                               Wicket.Log.info(busyChannel + " - ignoring the 
Ajax call because there is a running request.");
+                       }
+                       return null;
                }
        },
        

Reply via email to