You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Antoine Angenieux <aa...@clinigrid.com> on 2013/08/08 15:24:26 UTC

How to force an ajax channel to await that all other ajax channels are not busy before executing its scheduled callbacks?

Hi all!

In our application, we use two distinct Ajax Channels:
- The default one, using the default Queue type
- A dedicated channel for what we call "actions" of type Active

All "actions" use a same class of Behavior that sets the channel in the 
ajax attributes.

What I'd like to achieve is that whenever a callback is scheduled in the 
"action" channel, the action channel should wait that the default 
channel (or all other channels registered in the channel manager) is no 
longer busy before processing this callback.

Furthermore, I'd like that all attributes evaluation (being ajax 
attributes extra parameters or dynamic extra parameters) be deferred 
until no other channel is busy any more.

I was thinking of using an IAjaxCallListener in our ActionBehavior by 
implementing the getBeforeHandler() method. Looking at the 
Wicket.Channel and Wicket.ChannelManager, I guess it is relatively easy 
to determine whether any other channel is busy, but I don't see how I 
could defer the scheduling of the callback until then.

The other idea I came up with, but was not capable of implementing, is 
wrapping the getCallbackScript() of our ActionBehavior in a function 
that tests if any other channel is busy, and if so, simply reschedule 
its execution by calling window.setTimeout(). But then, I do not see a 
way to let this wrapping function return the result of the wrapped 
callback...

Does anyone have any idea on how to achieve this? Or if this is event 
possible?

Thank you in advance!

Cheers,

Antoine.

-- 
-------------
Antoine Angénieux
Co-founder
mob: +33 6 60 21 09 18
aangenieux@clinigrid.com
-------------
Clinigrid
92/98 boulevard Victor Hugo
93300 Clichy Cedex
Tel: +33 1 55 90 66 84
-------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to force an ajax channel to await that all other ajax channels are not busy before executing its scheduled callbacks?

Posted by Antoine Angenieux <aa...@clinigrid.com>.
Hi Martin,


Le 09/08/2013 09:29, Martin Grigorov a écrit :
> Hi,
>
> On Thu, Aug 8, 2013 at 5:12 PM, Antoine Angenieux
> <aa...@clinigrid.com>wrote:
>
>> Hi Martin,
>>

[...]

>>
>
> There is no reason to maintain a copy.
> All you need is a change in Channel(Manager) so you can extract the current
> code in my-channel-manager.js, add your changes and include it in the page
> after wicket-ajax-jquery.js so that it will override the namespace created
> by Wicket. Google "javascript monkey patching".

Ah, yes, thanks, that is a very good idea! I guess my limits on 
javascript code shines here ;)

>
>
>>
[...]

>>
>> If that is the case, I'm willing to discuss this and implement it so that
>> it may be integrated in Wicket later. Let me know if you're interested!
>>
>
> Sure. We are interested in improvements!
> If maven-clirr-plugin says it is API compatible and the current channel.js
> tests pass then we can include it in 6.x branch. But if there is an API
> break in Java it will have to wait for 7.0.0
>

Fantastic, I'll let you know what I have come up with. As a matter of 
fact, I am not so fond of the hierarchy principle when thinking about 
this issue, as I don't think its really understandable from a developper 
perspective. I'm leaning more towards a simple way to declare 
relationships between channels.

Thank you very much for your help!

Cheers,

Antoine.

------------
Antoine Angénieux
Co-founder
mob: +33 6 60 21 09 18
aangenieux@clinigrid.com
-------------
Clinigrid
92/98 boulevard Victor Hugo
93300 Clichy Cedex
Tel: +33 1 55 90 66 84
-------------

>
>>
>> Otherwise, maybe I could create a Wicketstuff project for this.
>>
>> Cheers,
>>
>> Antoine.
>>
>>
>> -------------
>> Antoine Angénieux
>> Co-founder
>> mob: +33 6 60 21 09 18
>> aangenieux@clinigrid.com
>> -------------
>> Clinigrid
>> 92/98 boulevard Victor Hugo
>> 93300 Clichy Cedex
>> Tel: +33 1 55 90 66 84
>> -------------
>>
>> Le 08/08/2013 16:48, Martin Grigorov a écrit :
>>
>>> Hi Antoine,
>>>
>>> All this is possible but it is not supported by Wicket's ChannelManager at
>>> the moment.
>>>
>>> There is one Channel instance per channel name. It is reachable thru
>>> Wicket.ChannelManager[**channelName]. This instance keeps an array of all
>>> scheduled functions (Wicket.Channel.callbacks).
>>> As far as I understand you you want to have this functionality for all
>>> channels, i.e. if there is a running request in channel1 with type Queue
>>> then channel2 should wait for it.
>>> Then in Channel.done() you have to notify all other channels when busy
>>> becomes false. Here the tricky part is to decide whether you want to keep
>>> order of the callbacks to execute in the other channels. I think there
>>> must
>>> be order.
>>>
>>> At the moment I'm not convinced that something like this should go in
>>> Wicket itself, so you will have to use monkey-patching to implement it and
>>> use it in your app.
>>> You may use
>>> https://github.com/apache/**wicket/blob/master/wicket-**
>>> core/src/test/js/channels.js<https://github.com/apache/wicket/blob/master/wicket-core/src/test/js/channels.js>
>>> as
>>> inspiration for unit testing your code.
>>>
>>>
>>>
>>> On Thu, Aug 8, 2013 at 3:24 PM, Antoine Angenieux
>>> <aa...@clinigrid.com>**wrote:
>>>
>>>   Hi all!
>>>>
>>>> In our application, we use two distinct Ajax Channels:
>>>> - The default one, using the default Queue type
>>>> - A dedicated channel for what we call "actions" of type Active
>>>>
>>>> All "actions" use a same class of Behavior that sets the channel in the
>>>> ajax attributes.
>>>>
>>>> What I'd like to achieve is that whenever a callback is scheduled in the
>>>> "action" channel, the action channel should wait that the default channel
>>>> (or all other channels registered in the channel manager) is no longer
>>>> busy
>>>> before processing this callback.
>>>>
>>>> Furthermore, I'd like that all attributes evaluation (being ajax
>>>> attributes extra parameters or dynamic extra parameters) be deferred
>>>> until
>>>> no other channel is busy any more.
>>>>
>>>> I was thinking of using an IAjaxCallListener in our ActionBehavior by
>>>> implementing the getBeforeHandler() method. Looking at the Wicket.Channel
>>>> and Wicket.ChannelManager, I guess it is relatively easy to determine
>>>> whether any other channel is busy, but I don't see how I could defer the
>>>> scheduling of the callback until then.
>>>>
>>>> The other idea I came up with, but was not capable of implementing, is
>>>> wrapping the getCallbackScript() of our ActionBehavior in a function that
>>>> tests if any other channel is busy, and if so, simply reschedule its
>>>> execution by calling window.setTimeout(). But then, I do not see a way to
>>>> let this wrapping function return the result of the wrapped callback...
>>>>
>>>> Does anyone have any idea on how to achieve this? Or if this is event
>>>> possible?
>>>>
>>>> Thank you in advance!
>>>>
>>>> Cheers,
>>>>
>>>> Antoine.
>>>>
>>>> --
>>>> -------------
>>>> Antoine Angénieux
>>>> Co-founder
>>>> mob: +33 6 60 21 09 18
>>>> aangenieux@clinigrid.com
>>>> -------------
>>>> Clinigrid
>>>> 92/98 boulevard Victor Hugo
>>>> 93300 Clichy Cedex
>>>> Tel: +33 1 55 90 66 84
>>>> -------------
>>>>
>>>> ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>>> <us...@wicket.apache.org>
>>>>>
>>>>
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to force an ajax channel to await that all other ajax channels are not busy before executing its scheduled callbacks?

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Thu, Aug 8, 2013 at 5:12 PM, Antoine Angenieux
<aa...@clinigrid.com>wrote:

> Hi Martin,
>
> Yes, it is what I was looking to achieve, and I was afraid that the only
> solution was to register in the IJavaScriptLibrarySettings an alternate
> version of the wicket-ajax-jquery.js script, as this would mean I'll have
> to keep it in sync with changes made to the origin scripts whenever I
> upgrade the wicket version I'm using.
>

There is no reason to maintain a copy.
All you need is a change in Channel(Manager) so you can extract the current
code in my-channel-manager.js, add your changes and include it in the page
after wicket-ajax-jquery.js so that it will override the namespace created
by Wicket. Google "javascript monkey patching".


>
> Thanks for your help, I'll look into the channels.js, as that might be a
> way for me to ensure that my own script works correctly both now and in
> future Wicket versions!
>
> I was wondering if some other people might need this feature, or
> alternatively in a feature allowing to either create a hierarchy of
> AjaxChannel instances.
>
> I was thinking of something along the lines:
>
> - Channel A
>  - Sub Channel A1
>    - Sub Channel A11
>  - ...
>
> where a sub channel would be able to process its callbacks stack only when
> its parent chanel is not busy.
>
> In the example above, Sub Channel A1 would be able to process its stack of
> callbacks only when Channel A is not busy anymore. And Channel A would
> notify its children when its busy state is set to false.
>
> On the Java side of the API, I would add another constructor taking a
> parent AjaxChannel as its parent.
>
> On the javascript side of the API, I'll enrich Channel and ChannelManager
> to be aware of the channels hierarchy, and handle the processing of the
> callback stacks and the notification of children channels whenever a busy
> parent channel is not busy anymore.
>
> I like this solution as it is (I think) fully compatible with the current
> behavior of channels.
>
> If that is the case, I'm willing to discuss this and implement it so that
> it may be integrated in Wicket later. Let me know if you're interested!
>

Sure. We are interested in improvements!
If maven-clirr-plugin says it is API compatible and the current channel.js
tests pass then we can include it in 6.x branch. But if there is an API
break in Java it will have to wait for 7.0.0


>
> Otherwise, maybe I could create a Wicketstuff project for this.
>
> Cheers,
>
> Antoine.
>
>
> -------------
> Antoine Angénieux
> Co-founder
> mob: +33 6 60 21 09 18
> aangenieux@clinigrid.com
> -------------
> Clinigrid
> 92/98 boulevard Victor Hugo
> 93300 Clichy Cedex
> Tel: +33 1 55 90 66 84
> -------------
>
> Le 08/08/2013 16:48, Martin Grigorov a écrit :
>
>> Hi Antoine,
>>
>> All this is possible but it is not supported by Wicket's ChannelManager at
>> the moment.
>>
>> There is one Channel instance per channel name. It is reachable thru
>> Wicket.ChannelManager[**channelName]. This instance keeps an array of all
>> scheduled functions (Wicket.Channel.callbacks).
>> As far as I understand you you want to have this functionality for all
>> channels, i.e. if there is a running request in channel1 with type Queue
>> then channel2 should wait for it.
>> Then in Channel.done() you have to notify all other channels when busy
>> becomes false. Here the tricky part is to decide whether you want to keep
>> order of the callbacks to execute in the other channels. I think there
>> must
>> be order.
>>
>> At the moment I'm not convinced that something like this should go in
>> Wicket itself, so you will have to use monkey-patching to implement it and
>> use it in your app.
>> You may use
>> https://github.com/apache/**wicket/blob/master/wicket-**
>> core/src/test/js/channels.js<https://github.com/apache/wicket/blob/master/wicket-core/src/test/js/channels.js>
>> as
>> inspiration for unit testing your code.
>>
>>
>>
>> On Thu, Aug 8, 2013 at 3:24 PM, Antoine Angenieux
>> <aa...@clinigrid.com>**wrote:
>>
>>  Hi all!
>>>
>>> In our application, we use two distinct Ajax Channels:
>>> - The default one, using the default Queue type
>>> - A dedicated channel for what we call "actions" of type Active
>>>
>>> All "actions" use a same class of Behavior that sets the channel in the
>>> ajax attributes.
>>>
>>> What I'd like to achieve is that whenever a callback is scheduled in the
>>> "action" channel, the action channel should wait that the default channel
>>> (or all other channels registered in the channel manager) is no longer
>>> busy
>>> before processing this callback.
>>>
>>> Furthermore, I'd like that all attributes evaluation (being ajax
>>> attributes extra parameters or dynamic extra parameters) be deferred
>>> until
>>> no other channel is busy any more.
>>>
>>> I was thinking of using an IAjaxCallListener in our ActionBehavior by
>>> implementing the getBeforeHandler() method. Looking at the Wicket.Channel
>>> and Wicket.ChannelManager, I guess it is relatively easy to determine
>>> whether any other channel is busy, but I don't see how I could defer the
>>> scheduling of the callback until then.
>>>
>>> The other idea I came up with, but was not capable of implementing, is
>>> wrapping the getCallbackScript() of our ActionBehavior in a function that
>>> tests if any other channel is busy, and if so, simply reschedule its
>>> execution by calling window.setTimeout(). But then, I do not see a way to
>>> let this wrapping function return the result of the wrapped callback...
>>>
>>> Does anyone have any idea on how to achieve this? Or if this is event
>>> possible?
>>>
>>> Thank you in advance!
>>>
>>> Cheers,
>>>
>>> Antoine.
>>>
>>> --
>>> -------------
>>> Antoine Angénieux
>>> Co-founder
>>> mob: +33 6 60 21 09 18
>>> aangenieux@clinigrid.com
>>> -------------
>>> Clinigrid
>>> 92/98 boulevard Victor Hugo
>>> 93300 Clichy Cedex
>>> Tel: +33 1 55 90 66 84
>>> -------------
>>>
>>> ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>> <us...@wicket.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to force an ajax channel to await that all other ajax channels are not busy before executing its scheduled callbacks?

Posted by Antoine Angenieux <aa...@clinigrid.com>.
Hi Martin,

Yes, it is what I was looking to achieve, and I was afraid that the only 
solution was to register in the IJavaScriptLibrarySettings an alternate 
version of the wicket-ajax-jquery.js script, as this would mean I'll 
have to keep it in sync with changes made to the origin scripts whenever 
I upgrade the wicket version I'm using.

Thanks for your help, I'll look into the channels.js, as that might be a 
way for me to ensure that my own script works correctly both now and in 
future Wicket versions!

I was wondering if some other people might need this feature, or 
alternatively in a feature allowing to either create a hierarchy of 
AjaxChannel instances.

I was thinking of something along the lines:

- Channel A
  - Sub Channel A1
    - Sub Channel A11
  - ...

where a sub channel would be able to process its callbacks stack only 
when its parent chanel is not busy.

In the example above, Sub Channel A1 would be able to process its stack 
of callbacks only when Channel A is not busy anymore. And Channel A 
would notify its children when its busy state is set to false.

On the Java side of the API, I would add another constructor taking a 
parent AjaxChannel as its parent.

On the javascript side of the API, I'll enrich Channel and 
ChannelManager to be aware of the channels hierarchy, and handle the 
processing of the callback stacks and the notification of children 
channels whenever a busy parent channel is not busy anymore.

I like this solution as it is (I think) fully compatible with the 
current behavior of channels.

If that is the case, I'm willing to discuss this and implement it so 
that it may be integrated in Wicket later. Let me know if you're interested!

Otherwise, maybe I could create a Wicketstuff project for this.

Cheers,

Antoine.

-------------
Antoine Angénieux
Co-founder
mob: +33 6 60 21 09 18
aangenieux@clinigrid.com
-------------
Clinigrid
92/98 boulevard Victor Hugo
93300 Clichy Cedex
Tel: +33 1 55 90 66 84
-------------

Le 08/08/2013 16:48, Martin Grigorov a écrit :
> Hi Antoine,
>
> All this is possible but it is not supported by Wicket's ChannelManager at
> the moment.
>
> There is one Channel instance per channel name. It is reachable thru
> Wicket.ChannelManager[channelName]. This instance keeps an array of all
> scheduled functions (Wicket.Channel.callbacks).
> As far as I understand you you want to have this functionality for all
> channels, i.e. if there is a running request in channel1 with type Queue
> then channel2 should wait for it.
> Then in Channel.done() you have to notify all other channels when busy
> becomes false. Here the tricky part is to decide whether you want to keep
> order of the callbacks to execute in the other channels. I think there must
> be order.
>
> At the moment I'm not convinced that something like this should go in
> Wicket itself, so you will have to use monkey-patching to implement it and
> use it in your app.
> You may use
> https://github.com/apache/wicket/blob/master/wicket-core/src/test/js/channels.js
> as
> inspiration for unit testing your code.
>
>
>
> On Thu, Aug 8, 2013 at 3:24 PM, Antoine Angenieux
> <aa...@clinigrid.com>wrote:
>
>> Hi all!
>>
>> In our application, we use two distinct Ajax Channels:
>> - The default one, using the default Queue type
>> - A dedicated channel for what we call "actions" of type Active
>>
>> All "actions" use a same class of Behavior that sets the channel in the
>> ajax attributes.
>>
>> What I'd like to achieve is that whenever a callback is scheduled in the
>> "action" channel, the action channel should wait that the default channel
>> (or all other channels registered in the channel manager) is no longer busy
>> before processing this callback.
>>
>> Furthermore, I'd like that all attributes evaluation (being ajax
>> attributes extra parameters or dynamic extra parameters) be deferred until
>> no other channel is busy any more.
>>
>> I was thinking of using an IAjaxCallListener in our ActionBehavior by
>> implementing the getBeforeHandler() method. Looking at the Wicket.Channel
>> and Wicket.ChannelManager, I guess it is relatively easy to determine
>> whether any other channel is busy, but I don't see how I could defer the
>> scheduling of the callback until then.
>>
>> The other idea I came up with, but was not capable of implementing, is
>> wrapping the getCallbackScript() of our ActionBehavior in a function that
>> tests if any other channel is busy, and if so, simply reschedule its
>> execution by calling window.setTimeout(). But then, I do not see a way to
>> let this wrapping function return the result of the wrapped callback...
>>
>> Does anyone have any idea on how to achieve this? Or if this is event
>> possible?
>>
>> Thank you in advance!
>>
>> Cheers,
>>
>> Antoine.
>>
>> --
>> -------------
>> Antoine Angénieux
>> Co-founder
>> mob: +33 6 60 21 09 18
>> aangenieux@clinigrid.com
>> -------------
>> Clinigrid
>> 92/98 boulevard Victor Hugo
>> 93300 Clichy Cedex
>> Tel: +33 1 55 90 66 84
>> -------------
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to force an ajax channel to await that all other ajax channels are not busy before executing its scheduled callbacks?

Posted by Martin Grigorov <mg...@apache.org>.
Hi Antoine,

All this is possible but it is not supported by Wicket's ChannelManager at
the moment.

There is one Channel instance per channel name. It is reachable thru
Wicket.ChannelManager[channelName]. This instance keeps an array of all
scheduled functions (Wicket.Channel.callbacks).
As far as I understand you you want to have this functionality for all
channels, i.e. if there is a running request in channel1 with type Queue
then channel2 should wait for it.
Then in Channel.done() you have to notify all other channels when busy
becomes false. Here the tricky part is to decide whether you want to keep
order of the callbacks to execute in the other channels. I think there must
be order.

At the moment I'm not convinced that something like this should go in
Wicket itself, so you will have to use monkey-patching to implement it and
use it in your app.
You may use
https://github.com/apache/wicket/blob/master/wicket-core/src/test/js/channels.js
as
inspiration for unit testing your code.



On Thu, Aug 8, 2013 at 3:24 PM, Antoine Angenieux
<aa...@clinigrid.com>wrote:

> Hi all!
>
> In our application, we use two distinct Ajax Channels:
> - The default one, using the default Queue type
> - A dedicated channel for what we call "actions" of type Active
>
> All "actions" use a same class of Behavior that sets the channel in the
> ajax attributes.
>
> What I'd like to achieve is that whenever a callback is scheduled in the
> "action" channel, the action channel should wait that the default channel
> (or all other channels registered in the channel manager) is no longer busy
> before processing this callback.
>
> Furthermore, I'd like that all attributes evaluation (being ajax
> attributes extra parameters or dynamic extra parameters) be deferred until
> no other channel is busy any more.
>
> I was thinking of using an IAjaxCallListener in our ActionBehavior by
> implementing the getBeforeHandler() method. Looking at the Wicket.Channel
> and Wicket.ChannelManager, I guess it is relatively easy to determine
> whether any other channel is busy, but I don't see how I could defer the
> scheduling of the callback until then.
>
> The other idea I came up with, but was not capable of implementing, is
> wrapping the getCallbackScript() of our ActionBehavior in a function that
> tests if any other channel is busy, and if so, simply reschedule its
> execution by calling window.setTimeout(). But then, I do not see a way to
> let this wrapping function return the result of the wrapped callback...
>
> Does anyone have any idea on how to achieve this? Or if this is event
> possible?
>
> Thank you in advance!
>
> Cheers,
>
> Antoine.
>
> --
> -------------
> Antoine Angénieux
> Co-founder
> mob: +33 6 60 21 09 18
> aangenieux@clinigrid.com
> -------------
> Clinigrid
> 92/98 boulevard Victor Hugo
> 93300 Clichy Cedex
> Tel: +33 1 55 90 66 84
> -------------
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>