Class Notifier

All Implemented Interfaces:

public class Notifier
extends Object
implements AutoCloseable
Notifiers run a callback function on a separate thread at a specified period.

If startSingle() is used, the callback will run once. If startPeriodic() is used, the callback will run repeatedly with the given period until stop() is called.

  • Constructor Details

    • Notifier

      public Notifier​(Runnable run)
      Create a Notifier for timer event notification.
      run - The handler that is called at the notification time which is set using StartSingle or StartPeriodic.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • setName

      public void setName​(String name)
      Sets the name of the notifier. Used for debugging purposes only.
      name - Name
    • setHandler

      public void setHandler​(Runnable handler)
      Change the handler function.
      handler - Handler
    • startSingle

      public void startSingle​(double delaySeconds)
      Register for single event notification. A timer event is queued for a single event after the specified delay.
      delaySeconds - Seconds to wait before the handler is called.
    • startPeriodic

      public void startPeriodic​(double periodSeconds)
      Register for periodic event notification. A timer event is queued for periodic event notification. Each time the interrupt occurs, the event will be immediately requeued for the same time interval.

      The user-provided callback should be written in a nonblocking manner so the callback can be recalled at the next periodic event notification.

      periodSeconds - Period in seconds to call the handler starting one period after the call to this method.
    • stop

      public void stop()
      Stop timer events from occurring. Stop any repeating timer events from occurring. This will also remove any single notification events from the queue. If a timer-based call to the registered handler is in progress, this function will block until the handler call is complete.
    • setHALThreadPriority

      public static boolean setHALThreadPriority​(boolean realTime, int priority)
      Sets the HAL notifier thread priority.

      The HAL notifier thread is responsible for managing the FPGA's notifier interrupt and waking up user's Notifiers when it's their time to run. Giving the HAL notifier thread real-time priority helps ensure the user's real-time Notifiers, if any, are notified to run in a timely manner.

      realTime - Set to true to set a real-time priority, false for standard priority.
      priority - Priority to set the thread to. For real-time, this is 1-99 with 99 being highest. For non-real-time, this is forced to 0. See "man 7 sched" for more details.
      True on success.