Class PeriodicPriorityQueue.Callback

java.lang.Object
org.wpilib.internal.PeriodicPriorityQueue.Callback
All Implemented Interfaces:
Comparable<PeriodicPriorityQueue.Callback>
Enclosing class:
PeriodicPriorityQueue

A periodic callback with scheduling metadata.

Each callback tracks its target function, period, and next expiration time. After execution, the expiration time is automatically advanced by full periods to maintain precise timing even when execution is delayed.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    long
    The next scheduled execution time in monotonic timestamp microseconds.
    final Runnable
    The function to execute when the callback fires.
    final long
    The period at which to run the callback in microseconds.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Callback(Runnable func, long timestamp, double periodSeconds)
    Construct a callback container.
    Callback(Runnable func, long timestamp, double periodSeconds, double offsetSeconds)
    Construct a callback container.
    Callback(Runnable func, long startTime, long period, long offset)
    Construct a callback container.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares this callback to another based on expiration time.
    boolean
    Compares callbacks based on expiration time for equality.
    int
    Returns a hash code based on the expiration time.

    Methods inherited from class Object

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

    • func

      public final Runnable func
      The function to execute when the callback fires.
    • period

      public final long period
      The period at which to run the callback in microseconds.
    • expirationTime

      public long expirationTime
      The next scheduled execution time in monotonic timestamp microseconds.
  • Constructor Details

    • Callback

      public Callback(Runnable func, long startTime, long period, long offset)
      Construct a callback container.
      Parameters:
      func - The callback to run.
      startTime - The common starting point for all callback scheduling in microseconds.
      period - The period at which to run the callback in microseconds.
      offset - The offset from the common starting time in microseconds.
    • Callback

      public Callback(Runnable func, long timestamp, double periodSeconds, double offsetSeconds)
      Construct a callback container.
      Parameters:
      func - The callback to run.
      timestamp - The common starting point for all callback scheduling in microseconds.
      periodSeconds - The period at which to run the callback in seconds.
      offsetSeconds - The offset from the common starting time in seconds.
    • Callback

      public Callback(Runnable func, long timestamp, double periodSeconds)
      Construct a callback container.
      Parameters:
      func - The callback to run.
      timestamp - The common starting point for all callback scheduling in microseconds.
      periodSeconds - The period at which to run the callback in seconds.
  • Method Details

    • equals

      public boolean equals(Object rhs)
      Compares callbacks based on expiration time for equality.
      Overrides:
      equals in class Object
      Parameters:
      rhs - The object to compare against.
      Returns:
      true if rhs is a Callback with the same expiration time.
    • hashCode

      public int hashCode()
      Returns a hash code based on the expiration time.
      Overrides:
      hashCode in class Object
      Returns:
      hash code for this callback.
    • compareTo

      Compares this callback to another based on expiration time.

      Callbacks with earlier expiration times are considered "less than" those with later expiration times. This ordering is used by the priority queue to determine execution order.

      Specified by:
      compareTo in interface Comparable<PeriodicPriorityQueue.Callback>
      Parameters:
      rhs - The callback to compare to.
      Returns:
      negative if this expires before rhs, positive if after, zero if equal.