当前位置: 首页>>代码示例>>Java>>正文


Java TimeInfo.computeDetails方法代码示例

本文整理汇总了Java中org.apache.commons.net.ntp.TimeInfo.computeDetails方法的典型用法代码示例。如果您正苦于以下问题:Java TimeInfo.computeDetails方法的具体用法?Java TimeInfo.computeDetails怎么用?Java TimeInfo.computeDetails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.net.ntp.TimeInfo的用法示例。


在下文中一共展示了TimeInfo.computeDetails方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOffset

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
private long getOffset(TimeInfo info) throws SystemTimeManagerException {
	NtpV3Packet message = info.getMessage();
	logStuff(info, message);
	info.computeDetails(); // compute offset/delay if not already done

	Long offsetValue = info.getOffset();
	Long delayValue = info.getDelay();
	log.info("Roundtrip delay=" + delayValue + "ms, clock offset="
			+ offsetValue + "ms");
	if (offsetValue == null) {
		throw new SystemTimeManagerException(
				"Could not get offset needed to adjust local clock to match remote clock");
	} else {
		return offsetValue;
	}
}
 
开发者ID:rafalmag,项目名称:EV3-projects,代码行数:17,代码来源:SystemTimeManager.java

示例2: run

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
@Override
public void run() {
	try {
		final TimeInfo info = get();
		info.computeDetails();
		EEWBot.instance.getClient().getDispatcher().dispatch(new TimeEvent(EEWBot.instance.getClient(), info));
		this.offset = getOffset(info);
	} catch (final IOException e) {
		Log.logger.error("NTPClient error", e);
	}
}
 
开发者ID:Team-Fruit,项目名称:EEWBot,代码行数:12,代码来源:NTPDispatcher.java

示例3: updateOffSet

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
private static void updateOffSet()
{
	//CREATE CLIENT
	NTPUDPClient client = new NTPUDPClient();
   
	//SET TIMEOUT
	client.setDefaultTimeout(10000);
	try 
	{
		//OPEN CLIENT
		client.open();
         
		//GET INFO FROM NTP SERVER
		InetAddress hostAddr = InetAddress.getByName(NTP_SERVER);
		TimeInfo info = client.getTime(hostAddr);
		info.computeDetails();
          
		//UPDATE OFFSET
		if(info.getOffset() != null)
		{
			offset = info.getOffset();
		} 
	} 
	catch (Exception e) 
	{
   	   	//ERROR GETTING OFFSET
	}

	client.close(); 
  }
 
开发者ID:razakal,项目名称:Qora,代码行数:31,代码来源:NTP.java

示例4: queryServerNow

import org.apache.commons.net.ntp.TimeInfo; //导入方法依赖的package包/类
private void queryServerNow() {
    Long offsetResult = null;
    for (int i = 0; i < MAX_QUERY_RETRIES; i++) {
        try {
            NTPUDPClient client = new NTPUDPClient();
            client.setDefaultTimeout(DEFAULT_NTP_TIMEOUT_MS);// Timeout if a response takes longer than 10 seconds

            client.open();
            InetAddress address = InetAddress.getByName(ntpServer);
            TimeInfo info = client.getTime(address);
            info.computeDetails();
            Long offset = info.getOffset();
            if (offset == null) {
                throw new Exception("Could not calculate time offset (offset is null)");
            } else {
                offsetResult = offset;
                break;
            }
        } catch (Exception e) {
            log.error("Error querying NTP server, attempt {} of {}", (i + 1), MAX_QUERY_RETRIES, e);
        }
    }

    if (offsetResult == null) {
        log.error("Could not successfully query NTP server after " + MAX_QUERY_RETRIES + " tries");
        throw new RuntimeException("Could not successfully query NTP server after " + MAX_QUERY_RETRIES + " tries");
    }

    lastOffsetGetTimeSystemMS = System.currentTimeMillis();
    lastOffsetMilliseconds = offsetResult;
    log.debug("Updated local time offset based on NTP server result. Offset = {}", lastOffsetMilliseconds);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:33,代码来源:NTPTimeSource.java


注:本文中的org.apache.commons.net.ntp.TimeInfo.computeDetails方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。