Class WaitDelayHandler

java.lang.Object
io.openems.edge.bridge.modbus.api.worker.internal.WaitDelayHandler

public class WaitDelayHandler extends Object
  • Constructor Details

    • WaitDelayHandler

      protected WaitDelayHandler(com.google.common.base.Ticker ticker, Runnable onWaitDelayTaskFinished, Consumer<Long> cycleDelayChannel)
    • WaitDelayHandler

      protected WaitDelayHandler(Runnable onWaitDelayTaskFinished, Consumer<Long> cycleDelayChannel)
  • Method Details

    • updateTotalNumberOfTasks

      public void updateTotalNumberOfTasks(int totalNumberOfTasks)
      Updates the size of the internal possibleDelays queue to the total number of tasks.

      'possibleDelays' needs to 'learn' execution time of all tasks, so it is important to keep its size in sync with the total number of tasks.

      Parameters:
      totalNumberOfTasks - the total number of tasks
    • onBeforeProcessImage

      public String onBeforeProcessImage(boolean traceLog)
      Called on BEFORE_PROCESS_IMAGE event.
      Parameters:
      traceLog - activate logging
      Returns:
      if traceLog is active, return a detailed log info; empty string otherwise
    • timeIsInvalid

      public void timeIsInvalid()
      Announce, that the Cycle measurement time is invalid.
      • WaitDelayTask will be set to 'zero-wait'
      • Internal marker 'timeIsInvalid' is set. This causes the time measurement for this Cycle to be ignored

      This method is called shortly after 'onBeforeProcessImage()'

    • onFinished

      public void onFinished()
      Called when waiting finished.
    • getWaitDelayTask

      public WaitTask.Delay getWaitDelayTask()
      Gets the WaitTask.Delay.
      Returns:
      the task
    • generateWaitDelayTask

      protected static WaitTask.Delay generateWaitDelayTask(Collection<Long> possibleDelays, Runnable onWaitDelayTaskFinished)
      Generates a
      invalid reference
      WaitDelayTask
      with the 1st 4th-quantile of all possible waiting times in the queue, i.e. one of the shortest possible delays - minus BUFFER_MS.
      Parameters:
      possibleDelays - the collected possible delays of the last Cycles
      onWaitDelayTaskFinished - callback on wait-delay finished
      Returns:
      the
      invalid reference
      WaitDelayTask