ikayaki.util
Class LastExecutor.RunDelayed

java.lang.Object
  extended by ikayaki.util.LastExecutor.RunDelayed
All Implemented Interfaces:
Comparable<Delayed>, Delayed
Enclosing class:
LastExecutor

private class LastExecutor.RunDelayed
extends Object
implements Delayed

Wraps a Runnable object and sets the delay after which it should be executed by a worker thread.

Author:
Esko Luontola

Field Summary
private  long expires
          The point in time when this RunDelayed will expire.
private  Runnable runnable
          Contained Runnable object to be run after this RunDelayed has expired.
 
Constructor Summary
LastExecutor.RunDelayed(Runnable runnable, int delayMillis)
          Creates a new RunDelayed item that contains runnable.
 
Method Summary
 int compareTo(Delayed delayed)
          Compares this object with the specified object for order.
 long getDelay(TimeUnit unit)
          Returns the remaining delay associated with this object, always in milliseconds.
 Runnable getRunnable()
          Returns the contained Runnable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

expires

private long expires
The point in time when this RunDelayed will expire.


runnable

private Runnable runnable
Contained Runnable object to be run after this RunDelayed has expired.

Constructor Detail

LastExecutor.RunDelayed

public LastExecutor.RunDelayed(Runnable runnable,
                               int delayMillis)
Creates a new RunDelayed item that contains runnable.

Parameters:
runnable - the Runnable to be contained
delayMillis - delay in milliseconds
Method Detail

getDelay

public long getDelay(TimeUnit unit)
Returns the remaining delay associated with this object, always in milliseconds.

Specified by:
getDelay in interface Delayed
Parameters:
unit - ignored; always assumed TimeUnit.MILLISECONDS
Returns:
the remaining delay; zero or negative values indicate that the delay has already elapsed

getRunnable

public Runnable getRunnable()
Returns the contained Runnable.

Returns:
the Runnable given as constructor parameter

compareTo

public int compareTo(Delayed delayed)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface Comparable<Delayed>
Parameters:
delayed - the Delayed to be compared.
Returns:
a negative integer, zero, or a positive integer as this delay is less than, equal to, or greater than the specified delay.