LimeWire Collection Component API

org.limewire.collection
Class Periodic

java.lang.Object
  extended by org.limewire.collection.Periodic

public class Periodic
extends Object

A utility to schedule, reschedule and cancel the execution of a task.

    Calendar cal = new GregorianCalendar();
    System.out.println("1) " + cal.get(Calendar.SECOND));

    Periodic p = new Periodic(new Runnable() {
        public void run() {
            Calendar cal = new GregorianCalendar();
            System.out.println("3) " + cal.get(Calendar.SECOND));
            }}, new SimpleTimer(false));

    p.rescheduleIfLater(5000);
    System.out.println("2) " + cal.get(Calendar.SECOND));

    Time run-dependant Output:
        1) 23
        2) 23
        3) 28


Constructor Summary
Periodic(Runnable r, ScheduledExecutorService scheduler)
          Creates a periodic task
 
Method Summary
protected  Runnable getRunnable()
           
 boolean rescheduleIfLater(long newDelay)
          changes the execution time of this Periodic task if it is later than the current execution time.
 boolean rescheduleIfSooner(long newDelay)
          changes the execution time of this Periodic task if it is sooner than the current execution time.
 void unschedule()
          Cancels any scheduled execution of the task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Periodic

public Periodic(Runnable r,
                ScheduledExecutorService scheduler)
Creates a periodic task

Parameters:
r - the Runnable to execute
scheduler - the SchedulingThreadPool to schedule execution on.
Method Detail

rescheduleIfLater

public boolean rescheduleIfLater(long newDelay)
changes the execution time of this Periodic task if it is later than the current execution time. Note: some implementations of ScheduledExecutorService use nanoseconds as their time unit, so do not schedule anything for more than 292 years in the future. More practically, this means you should not use Long.MAX_VALUE as parameter.

Parameters:
newDelay - the new delay from now when this should be executed
Returns:
true if the execution time changed

rescheduleIfSooner

public boolean rescheduleIfSooner(long newDelay)
changes the execution time of this Periodic task if it is sooner than the current execution time.

Parameters:
newDelay - the new delay from now when this should be executed
Returns:
true if the execution time changed

unschedule

public void unschedule()
Cancels any scheduled execution of the task.


getRunnable

protected Runnable getRunnable()

LimeWire Collection Component API

Copyright © 2009 Lime Wire LLC. All Rights Reserved.