Package ej.net.util
Class NtpUtil
- java.lang.Object
-
- ej.net.util.NtpUtil
-
public class NtpUtil extends Object
Utilities to update the local time using NTP.
-
-
Field Summary
Fields Modifier and Type Field Description static StringNTP_ATTEMPTS_PROPERTYProperty to set the NTP attempts.static intNTP_DEFAULT_ATTEMPTSDefault NTP attempts.static intNTP_DEFAULT_GUARD_TIMEDefault NTP guard time.static intNTP_DEFAULT_PORTDefault NTP port.static StringNTP_DEFAULT_SERVERDefault NTP URL.static intNTP_DEFAULT_TIMEOUTDefault NTP timeout.static StringNTP_GUARD_TIME_PROPERTYProperty to set the NTP guard time.static StringNTP_PORT_PROPERTYProperty to set the NTP port.static StringNTP_TIMEOUT_PROPERTYProperty to set the NTP timeout.static StringNTP_URL_PROPERTYProperty to set the NTP URL.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidupdateLocalTime()Updates the local time.static voidupdateLocalTime(String url, int port, int timeout)Updates the local time.
-
-
-
Field Detail
-
NTP_URL_PROPERTY
public static final String NTP_URL_PROPERTY
Property to set the NTP URL.- See Also:
- Constant Field Values
-
NTP_PORT_PROPERTY
public static final String NTP_PORT_PROPERTY
Property to set the NTP port.- See Also:
- Constant Field Values
-
NTP_TIMEOUT_PROPERTY
public static final String NTP_TIMEOUT_PROPERTY
Property to set the NTP timeout.- See Also:
- Constant Field Values
-
NTP_ATTEMPTS_PROPERTY
public static final String NTP_ATTEMPTS_PROPERTY
Property to set the NTP attempts.- See Also:
- Constant Field Values
-
NTP_GUARD_TIME_PROPERTY
public static final String NTP_GUARD_TIME_PROPERTY
Property to set the NTP guard time.- See Also:
- Constant Field Values
-
NTP_DEFAULT_PORT
public static final int NTP_DEFAULT_PORT
Default NTP port.- See Also:
- Constant Field Values
-
NTP_DEFAULT_SERVER
public static final String NTP_DEFAULT_SERVER
Default NTP URL.- See Also:
- Constant Field Values
-
NTP_DEFAULT_TIMEOUT
public static final int NTP_DEFAULT_TIMEOUT
Default NTP timeout.- See Also:
- Constant Field Values
-
NTP_DEFAULT_ATTEMPTS
public static final int NTP_DEFAULT_ATTEMPTS
Default NTP attempts.- See Also:
- Constant Field Values
-
NTP_DEFAULT_GUARD_TIME
public static final int NTP_DEFAULT_GUARD_TIME
Default NTP guard time.- See Also:
- Constant Field Values
-
-
Method Detail
-
updateLocalTime
public static void updateLocalTime() throws IOExceptionUpdates the local time. It uses the properties "ntp.url", "ntp.port" and "ntp.timeout" to parameterize the NTP requests. The default values are "0.pool.ntp.org":123 with a timeout 1000.- Throws:
IOException- if an error occurred.
-
updateLocalTime
public static void updateLocalTime(String url, int port, int timeout) throws IOException
Updates the local time.When this method returns, the application time is updated.
- Parameters:
url- the NTP server URL.port- the NTP server port.timeout- the timeout for one NTP request.- Throws:
IOException- if an error occurred.- See Also:
Util.currentTimeMillis()
-
-