Skip to content

Commit

Permalink
NTP little refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed May 4, 2015
1 parent 96f5f0b commit fdb0e7d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/scala/ntp/NTP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import java.util.logging.Logger

import org.apache.commons.net.ntp.NTPUDPClient

import scala.util.Try


object NTP {
private val TIME_TILL_UPDATE = 1000 * 60 * 10L
Expand All @@ -15,7 +13,7 @@ object NTP {
private var lastUpdate: Long = 0
private var offset: Long = 0

def getTime = {
def getTime() = {
//CHECK IF OFFSET NEEDS TO BE UPDATED
if (System.currentTimeMillis() > lastUpdate + TIME_TILL_UPDATE) {
updateOffSet()
Expand All @@ -33,16 +31,16 @@ object NTP {
val client = new NTPUDPClient()
client.setDefaultTimeout(10000)

Try {
try {
client.open()

//GET INFO FROM NTP SERVER
val hostAddr = InetAddress.getByName(NTP_SERVER)
val info = client.getTime(hostAddr)
val info = client.getTime(InetAddress.getByName(NTP_SERVER))
info.computeDetails()

if (info.getOffset != null) offset = info.getOffset
} catch {
case t: Throwable => Logger.getGlobal.warning("Problems with NTP: " + t.getMessage)
} finally {
client.close()
}
client.close()
}
}

0 comments on commit fdb0e7d

Please sign in to comment.