Class TimeSyncServiceImpl

java.lang.Object
io.github.lunasaw.sip.common.service.impl.TimeSyncServiceImpl
All Implemented Interfaces:
TimeSyncService

@Service public class TimeSyncServiceImpl extends Object implements TimeSyncService
时间同步服务实现类 支持SIP和NTP两种校时方式
Author:
luna
  • Constructor Details

    • TimeSyncServiceImpl

      public TimeSyncServiceImpl()
  • Method Details

    • syncTimeFromSip

      public boolean syncTimeFromSip(String dateHeaderValue)
      Description copied from interface: TimeSyncService
      SIP校时 - 从Date头域解析时间并同步
      Specified by:
      syncTimeFromSip in interface TimeSyncService
      Parameters:
      dateHeaderValue - Date头域的值 (格式: yyyy-MM-dd'T'HH:mm:ss.SSS)
      Returns:
      是否同步成功
    • syncTimeFromNtp

      public boolean syncTimeFromNtp(String ntpServer)
      Description copied from interface: TimeSyncService
      NTP校时 - 从NTP服务器同步时间
      Specified by:
      syncTimeFromNtp in interface TimeSyncService
      Parameters:
      ntpServer - NTP服务器地址
      Returns:
      是否同步成功
    • getTimeOffset

      public long getTimeOffset()
      Description copied from interface: TimeSyncService
      获取当前系统与标准时间的偏差
      Specified by:
      getTimeOffset in interface TimeSyncService
      Returns:
      时间偏差(毫秒),正值表示本地时间快于标准时间
    • setTimeOffset

      public void setTimeOffset(long offset)
      Description copied from interface: TimeSyncService
      设置时间偏差
      Specified by:
      setTimeOffset in interface TimeSyncService
      Parameters:
      offset - 时间偏差(毫秒)
    • getCorrectedTime

      public java.time.LocalDateTime getCorrectedTime()
      Description copied from interface: TimeSyncService
      获取经过校时修正的当前时间
      Specified by:
      getCorrectedTime in interface TimeSyncService
      Returns:
      修正后的当前时间
    • needsTimeSync

      public boolean needsTimeSync()
      Description copied from interface: TimeSyncService
      检查是否需要校时 当时间偏差超过配置的阈值时返回true
      Specified by:
      needsTimeSync in interface TimeSyncService
      Returns:
      是否需要校时
    • getLastSyncTime

      public java.time.LocalDateTime getLastSyncTime()
      Description copied from interface: TimeSyncService
      获取上次校时的时间
      Specified by:
      getLastSyncTime in interface TimeSyncService
      Returns:
      上次校时的时间