Package org.apache.commons.net.ntp
Class NtpV3Impl
java.lang.Object
org.apache.commons.net.ntp.NtpV3Impl
- All Implemented Interfaces:
- NtpV3Packet
Implements 
NtpV3Packet to convert Java objects to and from the Network Time Protocol (NTP) data message header format described in RFC-1305.- 
Field SummaryFields inherited from interface org.apache.commons.net.ntp.NtpV3PacketLI_ALARM_CONDITION, LI_LAST_MINUTE_HAS_59_SECONDS, LI_LAST_MINUTE_HAS_61_SECONDS, LI_NO_WARNING, MODE_BROADCAST, MODE_CLIENT, MODE_CONTROL_MESSAGE, MODE_PRIVATE, MODE_RESERVED, MODE_SERVER, MODE_SYMMETRIC_ACTIVE, MODE_SYMMETRIC_PASSIVE, NTP_MAXCLOCK, NTP_MAXPOLL, NTP_MINCLOCK, NTP_MINPOLL, NTP_PORT, TYPE_DAYTIME, TYPE_ICMP, TYPE_NTP, TYPE_TIME, VERSION_3, VERSION_4
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleanCompares this object against the specified object.Returns the datagram packet with the NTP details already filled in.intReturns leap indicator as defined in RFC-1305 which is a two-bit code: 0=no warning 1=last minute has 61 seconds 2=last minute has 59 seconds 3=alarm condition (clock not synchronized)intgetMode()Returns mode as defined in RFC-1305 which is a 3-bit integer whose value is indicated by the MODE_xxx parameters.Return human-readable name of message mode type as described in RFC 1305.Returns theoriginatetime as defined in RFC-1305.intgetPoll()Returns poll interval as defined in RFC-1305, which is an eight-bit signed integer indicating the maximum interval between successive messages, in seconds to the nearest power of two (e.g.intReturns precision as defined in RFC-1305 encoded as an 8-bit signed integer (seconds to the nearest power of two).Returnsreceivetimestamp as defined in RFC-1305.intReturns the reference id as defined in RFC-1305, which is a 32-bit integer whose value is dependent on several criteria.Returns the reference id string.Returns the reference time as defined in RFC-1305.intReturn root delay as defined in RFC-1305, which is the total roundtrip delay to the primary reference source, in seconds.doubleReturn root delay as defined in RFC-1305 in milliseconds, which is the total roundtrip delay to the primary reference source, in seconds.intReturns root dispersion as defined in RFC-1305.longReturns root dispersion (as defined in RFC-1305) in milliseconds.doubleReturns root dispersion (as defined in RFC-1305) in milliseconds as double precision value.intReturns Stratum as defined in RFC-1305, which indicates the stratum level of the local clock, with values defined as follows: 0=unspecified, 1=primary ref clock, and all others a secondary reference (via NTP).Returns thetransmittimestamp as defined in RFC-1305.getType()Return type of time packet.intReturns NTP version number as defined in RFC-1305.inthashCode()Computes a hash code for this object.voidsetDatagramPacket(DatagramPacket srcDp) Sets the contents of this object from source datagram packet.voidsetLeapIndicator(int li) Sets leap indicator as defined in RFC-1305.voidsetMode(int mode) Sets mode as defined in RFC-1305.voidSets originate timestamp given NTP TimeStamp object.voidsetPoll(int poll) Sets poll interval as defined in RFC-1305.voidsetPrecision(int precision) Sets precision as defined in RFC-1305.voidSets receive timestamp given NTP TimeStamp object.voidsetReferenceId(int refId) Sets reference clock identifier field with 32-bit unsigned integer value.voidSets Reference time with NTP timestamp.voidsetRootDelay(int delay) Sets root delay as defined in RFC-1305.voidsetRootDispersion(int dispersion) Sets root dispersion as defined in RFC-1305.voidsetStratum(int stratum) Sets stratum level as defined in RFC-1305.voidSets transmit time with NTP timestamp.voidsetVersion(int version) Sets NTP version as defined in RFC-1305.toString()Returns details of NTP packet as a string.protected static final intui(byte b) Convert byte to unsigned integer.protected static final longul(byte b) Convert byte to unsigned long.
- 
Constructor Details- 
NtpV3Implpublic NtpV3Impl()Creates a new instance of NtpV3Impl
 
- 
- 
Method Details- 
uiConvert byte to unsigned integer. Java only has signed types, so we have to do more work to get unsigned ops.- Parameters:
- b- input byte
- Returns:
- unsigned int value of byte
 
- 
ulConvert byte to unsigned long. Java only has signed types, so we have to do more work to get unsigned ops- Parameters:
- b- input byte
- Returns:
- unsigned long value of byte
 
- 
equalsCompares this object against the specified object. The result istrueif and only if the argument is notnulland is aNtpV3Implobject that contains the same values as this object.
- 
getDatagramPacketReturns the datagram packet with the NTP details already filled in.- Specified by:
- getDatagramPacketin interface- NtpV3Packet
- Returns:
- a datagram packet.
 
- 
getLeapIndicatorReturns leap indicator as defined in RFC-1305 which is a two-bit code: 0=no warning 1=last minute has 61 seconds 2=last minute has 59 seconds 3=alarm condition (clock not synchronized)- Specified by:
- getLeapIndicatorin interface- NtpV3Packet
- Returns:
- leap indicator as defined in RFC-1305.
 
- 
getModeReturns mode as defined in RFC-1305 which is a 3-bit integer whose value is indicated by the MODE_xxx parameters.- Specified by:
- getModein interface- NtpV3Packet
- Returns:
- mode as defined in RFC-1305.
 
- 
getModeNameReturn human-readable name of message mode type as described in RFC 1305.- Specified by:
- getModeNamein interface- NtpV3Packet
- Returns:
- mode name as string.
 
- 
getOriginateTimeStampReturns theoriginatetime as defined in RFC-1305.- Specified by:
- getOriginateTimeStampin interface- NtpV3Packet
- Returns:
- the originatetime. Never returns null.
 
- 
getPollReturns poll interval as defined in RFC-1305, which is an eight-bit signed integer indicating the maximum interval between successive messages, in seconds to the nearest power of two (e.g. value of six indicates an interval of 64 seconds). The values that can appear in this field range from NTP_MINPOLL to NTP_MAXPOLL inclusive.- Specified by:
- getPollin interface- NtpV3Packet
- Returns:
- poll interval as defined in RFC-1305.
 
- 
getPrecisionReturns precision as defined in RFC-1305 encoded as an 8-bit signed integer (seconds to the nearest power of two). Values normally range from -6 to -20.- Specified by:
- getPrecisionin interface- NtpV3Packet
- Returns:
- precision as defined in RFC-1305.
 
- 
getReceiveTimeStampReturnsreceivetimestamp as defined in RFC-1305.- Specified by:
- getReceiveTimeStampin interface- NtpV3Packet
- Returns:
- the receivetime. Never returns null.
 
- 
getReferenceIdReturns the reference id as defined in RFC-1305, which is a 32-bit integer whose value is dependent on several criteria.- Specified by:
- getReferenceIdin interface- NtpV3Packet
- Returns:
- the reference id as defined in RFC-1305.
 
- 
getReferenceIdStringReturns the reference id string. String cannot be null but value is dependent on the version of the NTP spec supported and stratum level. Value can be an empty string, clock type string, IP address, or a hexadecimal string.- Specified by:
- getReferenceIdStringin interface- NtpV3Packet
- Returns:
- the reference id string.
 
- 
getReferenceTimeStampReturns the reference time as defined in RFC-1305.- Specified by:
- getReferenceTimeStampin interface- NtpV3Packet
- Returns:
- the reference time as TimeStampobject. Never returns null.
 
- 
getRootDelayReturn root delay as defined in RFC-1305, which is the total roundtrip delay to the primary reference source, in seconds. Values can take positive and negative values, depending on clock precision and skew.- Specified by:
- getRootDelayin interface- NtpV3Packet
- Returns:
- root delay as defined in RFC-1305.
 
- 
getRootDelayInMillisDoubleReturn root delay as defined in RFC-1305 in milliseconds, which is the total roundtrip delay to the primary reference source, in seconds. Values can take positive and negative values, depending on clock precision and skew.- Specified by:
- getRootDelayInMillisDoublein interface- NtpV3Packet
- Returns:
- root delay in milliseconds
 
- 
getRootDispersionReturns root dispersion as defined in RFC-1305.- Specified by:
- getRootDispersionin interface- NtpV3Packet
- Returns:
- root dispersion.
 
- 
getRootDispersionInMillisReturns root dispersion (as defined in RFC-1305) in milliseconds.- Specified by:
- getRootDispersionInMillisin interface- NtpV3Packet
- Returns:
- root dispersion in milliseconds
 
- 
getRootDispersionInMillisDoubleReturns root dispersion (as defined in RFC-1305) in milliseconds as double precision value.- Specified by:
- getRootDispersionInMillisDoublein interface- NtpV3Packet
- Returns:
- root dispersion in milliseconds
 
- 
getStratumReturns Stratum as defined in RFC-1305, which indicates the stratum level of the local clock, with values defined as follows: 0=unspecified, 1=primary ref clock, and all others a secondary reference (via NTP).- Specified by:
- getStratumin interface- NtpV3Packet
- Returns:
- Stratum level as defined in RFC-1305.
 
- 
getTransmitTimeStampReturns thetransmittimestamp as defined in RFC-1305.- Specified by:
- getTransmitTimeStampin interface- NtpV3Packet
- Returns:
- the transmittimestamp as defined in RFC-1305. Never returns a null object.
 
- 
getTypeReturn type of time packet. The values (e.g. NTP, TIME, ICMP, ...) correspond to the protocol used to obtain the timing information.- Specified by:
- getTypein interface- NtpV3Packet
- Returns:
- packet type string identifier which in this case is "NTP".
 
- 
getVersionReturns NTP version number as defined in RFC-1305.- Specified by:
- getVersionin interface- NtpV3Packet
- Returns:
- NTP version number.
 
- 
hashCodeComputes a hash code for this object. The result is the exclusive OR of the values of this object stored as a byte array.
- 
setDatagramPacketSets the contents of this object from source datagram packet.- Specified by:
- setDatagramPacketin interface- NtpV3Packet
- Parameters:
- srcDp- source DatagramPacket to copy contents from, never null.
- Throws:
- IllegalArgumentException- if srcDp is null or byte length is less than minimum length of 48 bytes
 
- 
setLeapIndicatorSets leap indicator as defined in RFC-1305.- Specified by:
- setLeapIndicatorin interface- NtpV3Packet
- Parameters:
- li- leap indicator.
 
- 
setModeSets mode as defined in RFC-1305.- Specified by:
- setModein interface- NtpV3Packet
- Parameters:
- mode- the mode to set
 
- 
setOriginateTimeStampSets originate timestamp given NTP TimeStamp object. Iftsis null then zero time is used.- Specified by:
- setOriginateTimeStampin interface- NtpV3Packet
- Parameters:
- ts- NTP timestamp
 
- 
setPollSets poll interval as defined in RFC-1305.- Specified by:
- setPollin interface- NtpV3Packet
- Parameters:
- poll- poll interval.
 
- 
setPrecisionSets precision as defined in RFC-1305.- Specified by:
- setPrecisionin interface- NtpV3Packet
- Parameters:
- precision- the precision to set
- Since:
- 3.4
 
- 
setReceiveTimeStampSets receive timestamp given NTP TimeStamp object. Iftsis null then zero time is used.- Specified by:
- setReceiveTimeStampin interface- NtpV3Packet
- Parameters:
- ts- timestamp
 
- 
setReferenceIdSets reference clock identifier field with 32-bit unsigned integer value. See RFC-1305 for description.- Specified by:
- setReferenceIdin interface- NtpV3Packet
- Parameters:
- refId- reference clock identifier.
 
- 
setReferenceTimeSets Reference time with NTP timestamp. Iftsis null then zero time is used.- Specified by:
- setReferenceTimein interface- NtpV3Packet
- Parameters:
- ts- NTP timestamp
 
- 
setRootDelaySets root delay as defined in RFC-1305.- Specified by:
- setRootDelayin interface- NtpV3Packet
- Parameters:
- delay- root delay
- Since:
- 3.4
 
- 
setRootDispersionSets root dispersion as defined in RFC-1305.- Specified by:
- setRootDispersionin interface- NtpV3Packet
- Parameters:
- dispersion- root dispersion
- Since:
- 3.4
 
- 
setStratumSets stratum level as defined in RFC-1305.- Specified by:
- setStratumin interface- NtpV3Packet
- Parameters:
- stratum- stratum level.
 
- 
setTransmitTimeSets transmit time with NTP timestamp. Iftsis null then zero time is used.- Specified by:
- setTransmitTimein interface- NtpV3Packet
- Parameters:
- ts- NTP timestamp
 
- 
setVersionSets NTP version as defined in RFC-1305.- Specified by:
- setVersionin interface- NtpV3Packet
- Parameters:
- version- NTP version.
 
- 
toStringReturns details of NTP packet as a string.
 
-