Class PeriodicPriorityQueue.Callback

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

public static class PeriodicPriorityQueue.Callback extends Object implements Comparable<PeriodicPriorityQueue.Callback>
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 nanoseconds.
    final Runnable
    The function to execute when the callback fires.
    final long
    The unique id for this callback to allow callbacks to be tracked and removed from the queue throughout robot operation.
    final long
    The period at which to run the callback in nanoseconds.
  • 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 their stable identity.
    int
    Returns a hash code based on the stable identity.

    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 nanoseconds.
    • expirationTime

      public long expirationTime
      The next scheduled execution time in monotonic timestamp nanoseconds.
    • id

      public final long id
      The unique id for this callback to allow callbacks to be tracked and removed from the queue throughout robot operation.
  • 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 nanoseconds.
      period - The period at which to run the callback in nanoseconds.
      offset - The offset from the common starting time in nanoseconds.
    • 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 nanoseconds.
      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 nanoseconds.
      periodSeconds - The period at which to run the callback in seconds.
  • Method Details

    • equals

      public boolean equals(Object rhs)
      Compares callbacks based on their stable identity.
      Overrides:
      equals in class Object
      Parameters:
      rhs - The object to compare against.
      Returns:
      true if rhs is the same Callback (same id).
    • hashCode

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

      public int compareTo(PeriodicPriorityQueue.Callback rhs)
      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.