All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.wicket.EverSlowingAbstractAjaxTimerBehavior Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
package com.databasesandlife.util.wicket;

import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.util.time.Duration;
import org.slf4j.LoggerFactory;

/**
 * The component will get updated, but ever less often.
 *   

* This means that initially the refresh rate is once a second, so the user will see the data updated quickly. * But after a while, it will gradually slow, until it reaches once a minute. *

* This is a good balance between the user seeing the data update frequently (at the beginning), * and not spamming our server if lots of people leave their web browsers open. * * @author This source is copyright Adrian Smith and licensed under the LGPL 3. * @see Project on GitHub */ @SuppressWarnings("serial") public abstract class EverSlowingAbstractAjaxTimerBehavior extends AbstractAjaxTimerBehavior { double durationSeconds = 1; final double durationMultipler = 1.25; final double maxSeconds = 60; public EverSlowingAbstractAjaxTimerBehavior() { super(Duration.seconds(1)); } abstract protected void onEverSlowingTimer(AjaxRequestTarget target); @Override protected final void onTimer(AjaxRequestTarget target) { onEverSlowingTimer(target); durationSeconds = Math.min(durationSeconds * durationMultipler, maxSeconds); LoggerFactory.getLogger(getClass()).debug(String.format("%s: duration =%5.1f seconds", getClass().getSimpleName(), durationSeconds)); setUpdateInterval(Duration.seconds(durationSeconds)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy