
org.directwebremoting.impl.TimedAlarm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwr Show documentation
Show all versions of dwr Show documentation
DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript.
It gets rid of almost all the boilerplate code between the web browser and your Java code.
This version 4.0.2 works with Jakarta Servlet 4.0.2.
The newest version!
package org.directwebremoting.impl;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.directwebremoting.extend.Alarm;
import org.directwebremoting.extend.Sleeper;
/**
* An Alarm that goes off after a certain length of time.
* @author Joe Walker [joe at getahead dot ltd dot uk]
*/
public class TimedAlarm implements Alarm
{
/**
* @param sleeper ...
* @param waitTime How long we wait before the Alarm goes off
* @param executor ...
*/
public TimedAlarm(final Sleeper sleeper, long waitTime, ScheduledThreadPoolExecutor executor)
{
if (waitTime == 0)
{
sleeper.wakeUpToClose();
}
else
{
Runnable runnable = new Runnable()
{
public void run()
{
sleeper.wakeUpToClose();
}
};
future = executor.schedule(runnable, waitTime, TimeUnit.MILLISECONDS);
}
}
public void cancel()
{
if (future != null)
{
future.cancel(true);
}
}
/**
* The future result that allows us to cancel the timer
*/
private ScheduledFuture> future;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy