Updated Branches: refs/heads/master a4f964d47 -> 6c3840a15
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/6c3840a1 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/6c3840a1 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/6c3840a1 Branch: refs/heads/master Commit: 6c3840a15130c07370adf1904cca03fcdbd71bf4 Parents: a4f964d Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Jul 23 16:00:05 2012 +0300 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Jul 23 16:00:05 2012 +0300 ---------------------------------------------------------------------- .../java/org/apache/wicket/ajax/AjaxChannel.java | 34 ++++++++++++-- .../wicket/ajax/res/js/wicket-ajax-jquery.js | 12 +++-- 2 files changed, 37 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/6c3840a1/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 55f79c1..d7bead8 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 @@ -26,7 +26,8 @@ import org.apache.wicket.util.lang.Args; * <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 @@ -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/6c3840a1/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js index fa46f1c..f57c5db 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js @@ -218,9 +218,9 @@ Wicket.Channel.prototype = { initialize: function (name) { name = name || '0|s'; - var res = name.match(/^([^|]+)\|(d|s)$/); + var res = name.match(/^([^|]+)\|(d|s|a)$/); if (isUndef(res)) { - this.name = ''; + this.name = '0'; // '0' is the default channel name this.type = 's'; // default to stack } else { @@ -241,13 +241,17 @@ Wicket.Log.error("An error occurred while executing Ajax request:" + exception); } } else { - Wicket.Log.info("Channel busy - postponing..."); + 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; + } else if (this.type === 'a') { // active + Wicket.Log.info(busyChannel + " - ignoring the Ajax call because there is a running request."); } return null; }
