You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Behrooz Nobakht <no...@gmail.com> on 2013/09/30 14:12:15 UTC

AjaxSelfUpdatingTimerBehavior does not stop itself properly after certain time

Hello,

I have a custom AjaxSelfUpdatingTimerBehavior as follows:

public class LimitedAjaxSelfUpdatingTimerBehavior extends
AjaxSelfUpdatingTimerBehavior {
    private static final long serialVersionUID = 1L;

    public static final long MAX_IDLE_TIME = TimeUnit.SECONDS.toMillis(120);

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private final AtomicLong createdTime = new
AtomicLong(System.currentTimeMillis());

    private final AtomicBoolean expired = new AtomicBoolean(false);

    public LimitedAjaxSelfUpdatingTimerBehavior() {
        this(Duration.milliseconds(MAX_IDLE_TIME));
    }

    protected LimitedAjaxSelfUpdatingTimerBehavior(Duration updateInterval) {
        super(updateInterval);
    }

    @Override
    protected final void onPostProcessTarget(AjaxRequestTarget target) {
        if (expired.get()) {
            stop(target);
            return;
        }
        doProcessTarget(target);
    }

    @Override
    protected boolean shouldTrigger() {
        long idle = System.currentTimeMillis() - createdTime.get();
        expired.compareAndSet(false, idle > MAX_IDLE_TIME);
        if (expired.get()) {
            logger.warn("A message");

            // find the AJAX request and stop it
            AjaxRequestTarget target =
RequestCycle.get().find(AjaxRequestTarget.class);
            stop(target);
        }
        return !expired.get();
    }

    /**
     * @param target
     */
    protected void doProcessTarget(AjaxRequestTarget target) {
    }
}

I use this behavior on a set of my components in a Wicket page, however,
after the default timeout passes, I can still see in the browser debug
console XHR requests such as:

http://localhost:8081/w/wicket/page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance&_=1380542862344

And the response to such XHR looks like:

<ajax-response>
<evaluate encoding="wicket1">
<![CDATA[
(function(){Wicket.TimerHandles['instance103']^ =
setTimeout('Wicket.Ajax.ajax({\"u\":\"./page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance\",\"c\":\"instance103\"});',
10000)})();
]]>

</evaluate>

</ajax-response>

which shows that the behavior has *not* been stopped for the component.

What am I missing or doing in a wrong way?

Thanks for the help!— Behrooz Nobakht

Re: AjaxSelfUpdatingTimerBehavior does not stop itself properly after certain time

Posted by Martin Grigorov <mg...@apache.org>.
doProcessTarget() is your own method and AFAIS it is called only if not
expired.

@Override
    protected final void onPostProcessTarget(AjaxRequestTarget target) {
        if (expired.get()) {
            stop(target);
            return;
        }
        doProcessTarget(target);
    }

Wicket knows nothing about this method, so it cannot call it.



On Mon, Sep 30, 2013 at 3:52 PM, Behrooz Nobakht <no...@gmail.com> wrote:

> Thanks for the hint. The part that "delete
> Wicket.TimerHandles[‘instance103’]" should be in the response, helped us
> find the issue.
>
> However, there is a more general discussion as this cannot be called a bug.
> Why after the last time “shouldTrigger” is called and then
> “stop(AjaxRequestTargte)”, there will be still another call to
> “doProcessTarget()”?
>
> This made us to use two flags to manage time-wise expiration of the
> behavior.
>
> Thanks,
>
>
> On Mon, Sep 30, 2013 at 2:23 PM, Martin Grigorov <mgrigorov@apache.org
> >wrote:
>
> > Hi,
> >
> > Put a breakpoint in #onPostProcessTarget() and make sure that
> stop(target)
> > is invoked.
> > Then check the Ajax response for this request and verify that it has
> > something like:
> >   delete Wicket.TimerHandles['instance103']
> > and that there is no another setTimeout() call in the <evaluation>
> elements
> > in the response.
> >
> > As last resort create a quickstart app and attach it to a ticket so we
> can
> > debug it and fix it if there is a problem.
> >
> >
> > On Mon, Sep 30, 2013 at 2:12 PM, Behrooz Nobakht <no...@gmail.com>
> wrote:
> >
> > > Hello,
> > >
> > > I have a custom AjaxSelfUpdatingTimerBehavior as follows:
> > >
> > > public class LimitedAjaxSelfUpdatingTimerBehavior extends
> > > AjaxSelfUpdatingTimerBehavior {
> > >     private static final long serialVersionUID = 1L;
> > >
> > >     public static final long MAX_IDLE_TIME =
> > > TimeUnit.SECONDS.toMillis(120);
> > >
> > >     private final Logger logger = LoggerFactory.getLogger(getClass());
> > >
> > >     private final AtomicLong createdTime = new
> > > AtomicLong(System.currentTimeMillis());
> > >
> > >     private final AtomicBoolean expired = new AtomicBoolean(false);
> > >
> > >     public LimitedAjaxSelfUpdatingTimerBehavior() {
> > >         this(Duration.milliseconds(MAX_IDLE_TIME));
> > >     }
> > >
> > >     protected LimitedAjaxSelfUpdatingTimerBehavior(Duration
> > > updateInterval) {
> > >         super(updateInterval);
> > >     }
> > >
> > >     @Override
> > >     protected final void onPostProcessTarget(AjaxRequestTarget target)
> {
> > >         if (expired.get()) {
> > >             stop(target);
> > >             return;
> > >         }
> > >         doProcessTarget(target);
> > >     }
> > >
> > >     @Override
> > >     protected boolean shouldTrigger() {
> > >         long idle = System.currentTimeMillis() - createdTime.get();
> > >         expired.compareAndSet(false, idle > MAX_IDLE_TIME);
> > >         if (expired.get()) {
> > >             logger.warn("A message");
> > >
> > >             // find the AJAX request and stop it
> > >             AjaxRequestTarget target =
> > > RequestCycle.get().find(AjaxRequestTarget.class);
> > >             stop(target);
> > >         }
> > >         return !expired.get();
> > >     }
> > >
> > >     /**
> > >      * @param target
> > >      */
> > >     protected void doProcessTarget(AjaxRequestTarget target) {
> > >     }
> > > }
> > >
> > > I use this behavior on a set of my components in a Wicket page,
> however,
> > > after the default timeout passes, I can still see in the browser debug
> > > console XHR requests such as:
> > >
> > >
> > >
> >
> http://localhost:8081/w/wicket/page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance&_=1380542862344
> > >
> > > And the response to such XHR looks like:
> > >
> > > <ajax-response>
> > > <evaluate encoding="wicket1">
> > > <![CDATA[
> > > (function(){Wicket.TimerHandles['instance103']^ =
> > >
> > >
> >
> setTimeout('Wicket.Ajax.ajax({\"u\":\"./page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance\",\"c\":\"instance103\"});',
> > > 10000)})();
> > > ]]>
> > >
> > > </evaluate>
> > >
> > > </ajax-response>
> > >
> > > which shows that the behavior has *not* been stopped for the component.
> > >
> > > What am I missing or doing in a wrong way?
> > >
> > > Thanks for the help!— Behrooz Nobakht
> > >
> >
>
>
>
> --
> -- Behrooz Nobakht
>

Re: AjaxSelfUpdatingTimerBehavior does not stop itself properly after certain time

Posted by Behrooz Nobakht <no...@gmail.com>.
Thanks for the hint. The part that "delete
Wicket.TimerHandles[‘instance103’]" should be in the response, helped us
find the issue.

However, there is a more general discussion as this cannot be called a bug.
Why after the last time “shouldTrigger” is called and then
“stop(AjaxRequestTargte)”, there will be still another call to
“doProcessTarget()”?

This made us to use two flags to manage time-wise expiration of the
behavior.

Thanks,


On Mon, Sep 30, 2013 at 2:23 PM, Martin Grigorov <mg...@apache.org>wrote:

> Hi,
>
> Put a breakpoint in #onPostProcessTarget() and make sure that stop(target)
> is invoked.
> Then check the Ajax response for this request and verify that it has
> something like:
>   delete Wicket.TimerHandles['instance103']
> and that there is no another setTimeout() call in the <evaluation> elements
> in the response.
>
> As last resort create a quickstart app and attach it to a ticket so we can
> debug it and fix it if there is a problem.
>
>
> On Mon, Sep 30, 2013 at 2:12 PM, Behrooz Nobakht <no...@gmail.com> wrote:
>
> > Hello,
> >
> > I have a custom AjaxSelfUpdatingTimerBehavior as follows:
> >
> > public class LimitedAjaxSelfUpdatingTimerBehavior extends
> > AjaxSelfUpdatingTimerBehavior {
> >     private static final long serialVersionUID = 1L;
> >
> >     public static final long MAX_IDLE_TIME =
> > TimeUnit.SECONDS.toMillis(120);
> >
> >     private final Logger logger = LoggerFactory.getLogger(getClass());
> >
> >     private final AtomicLong createdTime = new
> > AtomicLong(System.currentTimeMillis());
> >
> >     private final AtomicBoolean expired = new AtomicBoolean(false);
> >
> >     public LimitedAjaxSelfUpdatingTimerBehavior() {
> >         this(Duration.milliseconds(MAX_IDLE_TIME));
> >     }
> >
> >     protected LimitedAjaxSelfUpdatingTimerBehavior(Duration
> > updateInterval) {
> >         super(updateInterval);
> >     }
> >
> >     @Override
> >     protected final void onPostProcessTarget(AjaxRequestTarget target) {
> >         if (expired.get()) {
> >             stop(target);
> >             return;
> >         }
> >         doProcessTarget(target);
> >     }
> >
> >     @Override
> >     protected boolean shouldTrigger() {
> >         long idle = System.currentTimeMillis() - createdTime.get();
> >         expired.compareAndSet(false, idle > MAX_IDLE_TIME);
> >         if (expired.get()) {
> >             logger.warn("A message");
> >
> >             // find the AJAX request and stop it
> >             AjaxRequestTarget target =
> > RequestCycle.get().find(AjaxRequestTarget.class);
> >             stop(target);
> >         }
> >         return !expired.get();
> >     }
> >
> >     /**
> >      * @param target
> >      */
> >     protected void doProcessTarget(AjaxRequestTarget target) {
> >     }
> > }
> >
> > I use this behavior on a set of my components in a Wicket page, however,
> > after the default timeout passes, I can still see in the browser debug
> > console XHR requests such as:
> >
> >
> >
> http://localhost:8081/w/wicket/page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance&_=1380542862344
> >
> > And the response to such XHR looks like:
> >
> > <ajax-response>
> > <evaluate encoding="wicket1">
> > <![CDATA[
> > (function(){Wicket.TimerHandles['instance103']^ =
> >
> >
> setTimeout('Wicket.Ajax.ajax({\"u\":\"./page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance\",\"c\":\"instance103\"});',
> > 10000)})();
> > ]]>
> >
> > </evaluate>
> >
> > </ajax-response>
> >
> > which shows that the behavior has *not* been stopped for the component.
> >
> > What am I missing or doing in a wrong way?
> >
> > Thanks for the help!— Behrooz Nobakht
> >
>



-- 
-- Behrooz Nobakht

Re: AjaxSelfUpdatingTimerBehavior does not stop itself properly after certain time

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

Put a breakpoint in #onPostProcessTarget() and make sure that stop(target)
is invoked.
Then check the Ajax response for this request and verify that it has
something like:
  delete Wicket.TimerHandles['instance103']
and that there is no another setTimeout() call in the <evaluation> elements
in the response.

As last resort create a quickstart app and attach it to a ticket so we can
debug it and fix it if there is a problem.


On Mon, Sep 30, 2013 at 2:12 PM, Behrooz Nobakht <no...@gmail.com> wrote:

> Hello,
>
> I have a custom AjaxSelfUpdatingTimerBehavior as follows:
>
> public class LimitedAjaxSelfUpdatingTimerBehavior extends
> AjaxSelfUpdatingTimerBehavior {
>     private static final long serialVersionUID = 1L;
>
>     public static final long MAX_IDLE_TIME =
> TimeUnit.SECONDS.toMillis(120);
>
>     private final Logger logger = LoggerFactory.getLogger(getClass());
>
>     private final AtomicLong createdTime = new
> AtomicLong(System.currentTimeMillis());
>
>     private final AtomicBoolean expired = new AtomicBoolean(false);
>
>     public LimitedAjaxSelfUpdatingTimerBehavior() {
>         this(Duration.milliseconds(MAX_IDLE_TIME));
>     }
>
>     protected LimitedAjaxSelfUpdatingTimerBehavior(Duration
> updateInterval) {
>         super(updateInterval);
>     }
>
>     @Override
>     protected final void onPostProcessTarget(AjaxRequestTarget target) {
>         if (expired.get()) {
>             stop(target);
>             return;
>         }
>         doProcessTarget(target);
>     }
>
>     @Override
>     protected boolean shouldTrigger() {
>         long idle = System.currentTimeMillis() - createdTime.get();
>         expired.compareAndSet(false, idle > MAX_IDLE_TIME);
>         if (expired.get()) {
>             logger.warn("A message");
>
>             // find the AJAX request and stop it
>             AjaxRequestTarget target =
> RequestCycle.get().find(AjaxRequestTarget.class);
>             stop(target);
>         }
>         return !expired.get();
>     }
>
>     /**
>      * @param target
>      */
>     protected void doProcessTarget(AjaxRequestTarget target) {
>     }
> }
>
> I use this behavior on a set of my components in a Wicket page, however,
> after the default timeout passes, I can still see in the browser debug
> console XHR requests such as:
>
>
> http://localhost:8081/w/wicket/page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance&_=1380542862344
>
> And the response to such XHR looks like:
>
> <ajax-response>
> <evaluate encoding="wicket1">
> <![CDATA[
> (function(){Wicket.TimerHandles['instance103']^ =
>
> setTimeout('Wicket.Ajax.ajax({\"u\":\"./page?1-1.IBehaviorListener.0-serviceInstances-0-serviceInstanceServerInstances-content-servers-0-server-instances-0-instance\",\"c\":\"instance103\"});',
> 10000)})();
> ]]>
>
> </evaluate>
>
> </ajax-response>
>
> which shows that the behavior has *not* been stopped for the component.
>
> What am I missing or doing in a wrong way?
>
> Thanks for the help!— Behrooz Nobakht
>