Package org.apache.commons.net.ntp
Class TimeInfo
- java.lang.Object
-
- org.apache.commons.net.ntp.TimeInfo
-
public class TimeInfo extends java.lang.ObjectWrapper class to network time packet messages (NTP, etc.) that computes related timing info and stats.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>commentsprivate java.lang.LongdelayMillisprivate booleandetailsComputedflag indicating that the TimeInfo details was processed and delay/offset were computedprivate NtpV3Packetmessageprivate java.lang.LongoffsetMillisprivate longreturnTimeMillistime at which time message packet was received by local machine
-
Constructor Summary
Constructors Constructor Description TimeInfo(NtpV3Packet message, long returnTimeMillis)Create TimeInfo object with raw packet message and destination time received.TimeInfo(NtpV3Packet msgPacket, long returnTimeMillis, boolean doComputeDetails)Create TimeInfo object with raw packet message and destination time received.TimeInfo(NtpV3Packet message, long returnTimeMillis, java.util.List<java.lang.String> comments)Create TimeInfo object with raw packet message and destination time received.TimeInfo(NtpV3Packet message, long returnTimeMillis, java.util.List<java.lang.String> comments, boolean doComputeDetails)Create TimeInfo object with raw packet message and destination time received.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddComment(java.lang.String comment)Add comment (error/warning) to list of comments associated with processing of NTP parameters.voidcomputeDetails()Compute and validate details of the NTP message packet.booleanequals(java.lang.Object obj)Compares this object against the specified object.java.net.InetAddressgetAddress()Gets host address from message datagram if availablejava.util.List<java.lang.String>getComments()Gets the list of comments (if any) during processing of NTP packet.java.lang.LonggetDelay()Gets the round-trip network delay.NtpV3PacketgetMessage()Gets the NTP message packet.java.lang.LonggetOffset()Gets the clock offset needed to adjust local clock to match remote clock.longgetReturnTime()Gets the time at which time message packet was received by local machine.inthashCode()Computes a hash code for this object.
-
-
-
Field Detail
-
message
private final NtpV3Packet message
-
comments
private java.util.List<java.lang.String> comments
-
delayMillis
private java.lang.Long delayMillis
-
offsetMillis
private java.lang.Long offsetMillis
-
returnTimeMillis
private final long returnTimeMillis
time at which time message packet was received by local machine
-
detailsComputed
private boolean detailsComputed
flag indicating that the TimeInfo details was processed and delay/offset were computed
-
-
Constructor Detail
-
TimeInfo
public TimeInfo(NtpV3Packet message, long returnTimeMillis)
Create TimeInfo object with raw packet message and destination time received.- Parameters:
message- NTP message packetreturnTimeMillis- destination receive time- Throws:
java.lang.IllegalArgumentException- if message is null
-
TimeInfo
public TimeInfo(NtpV3Packet msgPacket, long returnTimeMillis, boolean doComputeDetails)
Create TimeInfo object with raw packet message and destination time received. Auto-computes details if computeDetails flag set otherwise this is delayed until computeDetails() is called. Delayed computation is for fast initialization when sub-millisecond timing is needed.- Parameters:
msgPacket- NTP message packetreturnTimeMillis- destination receive timedoComputeDetails- flag to pre-compute delay/offset values- Throws:
java.lang.IllegalArgumentException- if message is null
-
TimeInfo
public TimeInfo(NtpV3Packet message, long returnTimeMillis, java.util.List<java.lang.String> comments)
Create TimeInfo object with raw packet message and destination time received.- Parameters:
message- NTP message packetreturnTimeMillis- destination receive timecomments- List of errors/warnings identified during processing- Throws:
java.lang.IllegalArgumentException- if message is null
-
TimeInfo
public TimeInfo(NtpV3Packet message, long returnTimeMillis, java.util.List<java.lang.String> comments, boolean doComputeDetails)
Create TimeInfo object with raw packet message and destination time received. Auto-computes details if computeDetails flag set otherwise this is delayed until computeDetails() is called. Delayed computation is for fast initialization when sub-millisecond timing is needed.- Parameters:
message- NTP message packetreturnTimeMillis- destination receive timecomments- list of comments used to store errors/warnings with messagedoComputeDetails- flag to pre-compute delay/offset values- Throws:
java.lang.IllegalArgumentException- if message is null
-
-
Method Detail
-
addComment
public void addComment(java.lang.String comment)
Add comment (error/warning) to list of comments associated with processing of NTP parameters. If comment list not create then one will be created.- Parameters:
comment- the comment
-
computeDetails
public void computeDetails()
Compute and validate details of the NTP message packet. Computed fields include the offset and delay.
-
equals
public boolean equals(java.lang.Object obj)
Compares this object against the specified object. The result istrueif and only if the argument is notnulland is aTimeStampobject that contains the same values as this object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare with.- Returns:
trueif the objects are the same;falseotherwise.- Since:
- 3.4
-
getAddress
public java.net.InetAddress getAddress()
Gets host address from message datagram if available- Returns:
- host address of available otherwise null
- Since:
- 3.4
-
getComments
public java.util.List<java.lang.String> getComments()
Gets the list of comments (if any) during processing of NTP packet.- Returns:
- List or null if not yet computed
-
getDelay
public java.lang.Long getDelay()
Gets the round-trip network delay. If null then could not compute the delay.- Returns:
- Long or null if delay not available.
-
getMessage
public NtpV3Packet getMessage()
Gets the NTP message packet.- Returns:
- NTP message packet.
-
getOffset
public java.lang.Long getOffset()
Gets the clock offset needed to adjust local clock to match remote clock. If null then could not compute the offset.- Returns:
- Long or null if offset not available.
-
getReturnTime
public long getReturnTime()
Gets the time at which time message packet was received by local machine.- Returns:
- packet return time.
-
hashCode
public int hashCode()
Computes a hash code for this object. The result is the exclusive OR of the return time and the message hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this object.
- Since:
- 3.4
-
-