模块 wjybxx.base

类 Regulator

java.lang.Object
cn.wjybxx.base.time.Regulator

public class Regulator extends Object
频率调节器 - 可理解为轮询式Timer调度器。 它使用Timer的调度算法,但Timer是回调式的,Regulator是轮询式的。
作者:
wjybxx date 2023/4/4
  • 方法详细资料

    • newOnce

      public static Regulator newOnce(long firstDelay)
      参数:
      firstDelay - 首次执行延迟
    • newFixedDelay

      public static Regulator newFixedDelay(long firstDelay, long period)
      参数:
      firstDelay - 首次执行延迟
      period - 触发间隔
      返回:
      按固定延迟更新的调节器,它保证的是两次执行的间隔大于更新间隔
    • newFixedRate

      public static Regulator newFixedRate(long firstDelay, long period)
      参数:
      firstDelay - 首次执行延迟
      period - 触发间隔
      返回:
      按固定频率更新的调节器,它尽可能的保证总运行次数
    • restart

      public Regulator restart(long curTime)
      重新启动调节器 (没有单独的start方法,因为逻辑无区别)
      参数:
      curTime - 当前系统时间
      返回:
      this
    • isReady

      public boolean isReady(long curTime)
      参数:
      curTime - 当前系统时间
      返回:
      如果应该执行一次update或者tick,则返回true,否则返回false
    • forceReady

      public long forceReady(long curTime)
      强制使用当前时间更新调节器。
      参数:
      curTime - 当前系统时间
      返回:
      deltaTime
    • getDelay

      public long getDelay(long curTime)
      获取下次执行的延迟
    • correctTime

      public void correctTime(long curTime)
      校准时间
    • isPeriodic

      public boolean isPeriodic()
      返回:
      如果是周期性任务则返回true
    • getLastUpdateTime

      public long getLastUpdateTime()
      获取上次成功更新的时间戳 它的具体含义取悦于更新时使用的curTime的含义。
    • getDeltaTime

      public long getDeltaTime()
      如果是固定频率的调节器,应该使用getPeriod()获取更新间隔。 另外,返回值可能大于getPeriod()(其实可以设定最大返回值的,暂时没支持)
      返回:
      两次逻辑帧之间的间隔。
    • getCount

      public int getCount()
      已触发次数
    • getContext

      public Object getContext()
      任务关联的上下文
    • setContext

      public Regulator setContext(Object context)
    • getFirstDelay

      public long getFirstDelay()
    • setFirstDelay

      public void setFirstDelay(long firstDelay)
    • getPeriod

      public long getPeriod()
    • setPeriod

      public void setPeriod(long period)