Class DelayedEvent

java.lang.Object
cl.netswitch.lib.server.DelayedEvent
All Implemented Interfaces:
Comparable<Delayed>, Delayed

public abstract class DelayedEvent extends Object implements Delayed
Implements the logic common to all delayed events.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    DelayedEvent(long delay)
    Constructs a new DelayedEvent instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    Compares this DelayedEvent with the specified object for order.
    abstract void
    Dispatched this DelayedEvent to the target listener.
    final boolean
    equals(Object that)
    Indicates whether some other object is "equal to" this DelayedEvent.
    protected final long
    Returns the delay of this DelayedEvent (milliseconds).
    final long
    Returns the remaining delay in the given time unit.
    final int
    Returns a hash code value of this DelayedEvent.
    protected DelayedEvent
    Returns a new DelayedEvent for rescheduling (overridable).

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DelayedEvent

      protected DelayedEvent(long delay)
      Constructs a new DelayedEvent instance.
      Parameters:
      delay - the delay of this DelayedEvent (milliseconds).
      Throws:
      IllegalArgumentException - if delay is negative.
  • Method Details

    • getDelay

      protected final long getDelay()
      Returns the delay of this DelayedEvent (milliseconds).
      Returns:
      the delay of this DelayedEvent (milliseconds).
    • reschedule

      protected DelayedEvent reschedule()
      Returns a new DelayedEvent for rescheduling (overridable).
      Returns:
      a new DelayedEvent for rescheduling (overridable).
    • getDelay

      public final long getDelay(TimeUnit unit)
      Returns the remaining delay in the given time unit.
      Specified by:
      getDelay in interface Delayed
      Parameters:
      unit - the required time unit of the output
      Returns:
      the remaining delay in the given time unit.
      Throws:
      NullPointerException - if unit is null.
    • hashCode

      public final int hashCode()
      Returns a hash code value of this DelayedEvent.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value of this DelayedEvent.
    • equals

      public final boolean equals(Object that)
      Indicates whether some other object is "equal to" this DelayedEvent.
      Overrides:
      equals in class Object
      Parameters:
      that - the object to compare to this object (can be null).
      Returns:
      true if this delayed runnable equals that.
    • compareTo

      public final int compareTo(Delayed other)
      Compares this DelayedEvent with the specified object for order.
      Specified by:
      compareTo in interface Comparable<Delayed>
      Parameters:
      other - the object to compare to this DelayedEvent.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      Throws:
      NullPointerException - if other is null.
    • dispatch

      public abstract void dispatch() throws Exception
      Dispatched this DelayedEvent to the target listener.
      Throws:
      Exception - if an error occurs.