directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r124114 - incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message
Date Tue, 04 Jan 2005 15:41:25 GMT
Author: erodriguez
Date: Tue Jan  4 07:41:22 2005
New Revision: 124114

URL: http://svn.apache.org/viewcvs?view=rev&rev=124114
Log:
NTP header field type implementations.
Added:
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/LeapIndicatorType.java
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ModeType.java
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/StratumType.java

Added: incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/LeapIndicatorType.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/LeapIndicatorType.java?view=auto&rev=124114
==============================================================================
--- (empty file)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/LeapIndicatorType.java
Tue Jan  4 07:41:22 2005
@@ -0,0 +1,91 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.ntp.message;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Leap Indicator (LI): This is a two-bit code warning of an impending
+ * leap second to be inserted/deleted in the last minute of the current
+ * day, with bit 0 and bit 1, respectively, coded as follows:
+ *
+ *    LI       Value     Meaning
+ *    -------------------------------------------------------
+ *    00       0         no warning
+ *    01       1         last minute has 61 seconds
+ *    10       2         last minute has 59 seconds)
+ *    11       3         alarm condition (clock not synchronized)
+ */
+public final class LeapIndicatorType implements Comparable
+{
+	/**
+	 * Enumeration elements are constructed once upon class loading.
+	 * Order of appearance here determines the order of compareTo.
+	 */
+	public static final LeapIndicatorType NO_WARNING           = new LeapIndicatorType(0, "No
leap second warning.");
+	public static final LeapIndicatorType POSITIVE_LEAP_SECOND = new LeapIndicatorType(1, "Last
minute has 61 seconds.");
+	public static final LeapIndicatorType NEGATIVE_LEAP_SECOND = new LeapIndicatorType(2, "Last
minute has 59 seconds.");
+	public static final LeapIndicatorType ALARM_CONDITION      = new LeapIndicatorType(3, "Alarm
condition (clock not synchronized).");
+
+	public String toString()
+    {
+		return name;
+	}
+
+	public int compareTo( Object that )
+    {
+		return ordinal - ( (LeapIndicatorType) that ).ordinal;
+	}
+
+	public static LeapIndicatorType getTypeByOrdinal( int type )
+    {
+		for ( int ii = 0; ii < values.length; ii++ )
+			if ( values[ ii ].ordinal == type )
+				return values[ ii ];
+		return NO_WARNING;
+	}
+	
+	public int getOrdinal()
+    {
+		return ordinal;
+	}
+
+	/// PRIVATE /////
+	private final String name;
+	private final int    ordinal;
+
+	/**
+	 * Private constructor prevents construction outside of this class.
+	 */
+	private LeapIndicatorType( int ordinal, String name )
+    {
+        this.ordinal = ordinal;
+		this.name    = name;
+	}
+
+	/**
+	 * These two lines are all that's necessary to export a List of VALUES.
+	 */
+	private static final LeapIndicatorType[] values = { NO_WARNING, POSITIVE_LEAP_SECOND,
+			NEGATIVE_LEAP_SECOND, ALARM_CONDITION };
+	// VALUES needs to be located here, otherwise illegal forward reference
+	public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values )
);
+}
+

Added: incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ModeType.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ModeType.java?view=auto&rev=124114
==============================================================================
--- (empty file)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ModeType.java	Tue Jan
 4 07:41:22 2005
@@ -0,0 +1,98 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.ntp.message;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Mode: This is a three-bit integer indicating the mode, with values
+ * defined as follows:
+ *
+ *    Mode     Meaning
+ *    ------------------------------------
+ *    0        reserved
+ *    1        symmetric active
+ *    2        symmetric passive
+ *    3        client
+ *    4        server
+ *    5        broadcast
+ *    6        reserved for NTP control message
+ *    7        reserved for private use
+ */
+public final class ModeType implements Comparable
+{
+	/**
+	 * Enumeration elements are constructed once upon class loading.
+	 * Order of appearance here determines the order of compareTo.
+	 */
+	public static final ModeType RESERVED                 = new ModeType(0, "Reserved mode.");
+	public static final ModeType SYMMETRIC_ACTIVE         = new ModeType(1, "Symmetric active
mode.");
+	public static final ModeType RESERVED_PASSIVE         = new ModeType(2, "Symmetric passive
mode.");
+	public static final ModeType CLIENT                   = new ModeType(3, "Client mode.");
+	public static final ModeType SERVER                   = new ModeType(4, "Server mode.");
+	public static final ModeType BROADCAST                = new ModeType(5, "Broadcast mode.");
+	public static final ModeType RESERVED_FOR_NTP_CONTROL = new ModeType(6, "Reserved for NTP
control message.");
+	public static final ModeType RESERVED_FOR_PRIVATE_USE = new ModeType(7, "Reserved for private
use.");
+	
+	public String toString()
+    {
+		return name;
+	}
+
+	public int compareTo( Object that )
+    {
+		return ordinal - ( (ModeType) that ).ordinal;
+	}
+
+	public static ModeType getTypeByOrdinal( int type )
+    {
+		for ( int ii = 0; ii < values.length; ii++ )
+			if ( values[ ii ].ordinal == type )
+				return values[ ii ];
+		return SERVER;
+	}
+	
+	public int getOrdinal()
+    {
+		return ordinal;
+	}
+
+	/// PRIVATE /////
+	private final String name;
+	private final int    ordinal;
+
+	/**
+	 * Private constructor prevents construction outside of this class.
+	 */
+	private ModeType( int ordinal, String name )
+    {
+        this.ordinal = ordinal;
+		this.name    = name;
+	}
+
+	/**
+	 * These two lines are all that's necessary to export a List of VALUES.
+	 */
+	private static final ModeType[] values = { RESERVED, SYMMETRIC_ACTIVE, RESERVED_PASSIVE,
+			CLIENT, SERVER, BROADCAST, RESERVED_FOR_NTP_CONTROL, RESERVED_FOR_PRIVATE_USE };
+	// VALUES needs to be located here, otherwise illegal forward reference
+	public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values )
);
+}
+

Added: incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java?view=auto&rev=124114
==============================================================================
--- (empty file)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java
Tue Jan  4 07:41:22 2005
@@ -0,0 +1,117 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.ntp.message;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Reference Identifier: This is a 32-bit bitstring identifying the
+ * particular reference source. In the case of NTP Version 3 or Version
+ * 4 stratum-0 (unspecified) or stratum-1 (primary) servers, this is a
+ * four-character ASCII string, left justified and zero padded to 32
+ * bits. In NTP Version 3 secondary servers, this is the 32-bit IPv4
+ * address of the reference source. In NTP Version 4 secondary servers,
+ * this is the low order 32 bits of the latest transmit timestamp of the
+ * reference source. NTP primary (stratum 1) servers should set this
+ * field to a code identifying the external reference source according
+ * to the following list. If the external reference is one of those
+ * listed, the associated code should be used. Codes for sources not
+ * listed can be contrived as appropriate.
+ */
+public class ReferenceIdentifier implements Comparable
+{
+	/**
+	 * Enumeration elements are constructed once upon class loading.
+	 * Order of appearance here determines the order of compareTo.
+	 */
+	public static final ReferenceIdentifier INIT = new ReferenceIdentifier(0,  "INIT", "initializing");
+	public static final ReferenceIdentifier LOCL = new ReferenceIdentifier(1,  "LOCL", "uncalibrated
local clock");
+	public static final ReferenceIdentifier PPS  = new ReferenceIdentifier(2,  "PPL", "pulse-per-second
source");
+	public static final ReferenceIdentifier ACTS = new ReferenceIdentifier(3,  "ACTS", "NIST
dialup modem service");
+	public static final ReferenceIdentifier USNO = new ReferenceIdentifier(4,  "USNO", "USNO
modem service");
+	public static final ReferenceIdentifier PTB  = new ReferenceIdentifier(5,  "PTB", "PTB (Germany)
modem service");
+	public static final ReferenceIdentifier TDF  = new ReferenceIdentifier(6,  "TDF", "Allouis
(France) Radio 164 kHz");
+	public static final ReferenceIdentifier DCF  = new ReferenceIdentifier(7,  "DCF", "Mainflingen
(Germany) Radio 77.5 kHz");
+	public static final ReferenceIdentifier MSF  = new ReferenceIdentifier(8,  "MSF", "Rugby
(UK) Radio 60 kHz");
+	public static final ReferenceIdentifier WWV  = new ReferenceIdentifier(9,  "WWV", "Ft. Collins
(US) Radio 2.5, 5, 10, 15, 20 MHz");
+	public static final ReferenceIdentifier WWVB = new ReferenceIdentifier(10, "WWVB", "Boulder
(US) Radio 60 kHz");
+	public static final ReferenceIdentifier WWVH = new ReferenceIdentifier(11, "WWVH", "Kaui
Hawaii (US) Radio 2.5, 5, 10, 15 MHz");
+	public static final ReferenceIdentifier CHU  = new ReferenceIdentifier(12, "CHU", "Ottawa
(Canada) Radio 3330, 7335, 14670 kHz");
+	public static final ReferenceIdentifier LORC = new ReferenceIdentifier(13, "LORC", "LORAN-C
radionavigation system");
+	public static final ReferenceIdentifier OMEG = new ReferenceIdentifier(14, "OMEG", "OMEGA
radionavigation system");
+	public static final ReferenceIdentifier GPS  = new ReferenceIdentifier(15, "GPS", "Global
Positioning Service");
+	public static final ReferenceIdentifier GOES = new ReferenceIdentifier(16, "GOES", "Geostationary
Orbit Environment Satellite");
+	public static final ReferenceIdentifier CDMA = new ReferenceIdentifier(17, "CDMA", "CDMA
mobile cellular/PCS telephone system");
+	
+	public String toString()
+    {
+		return name;
+	}
+
+	public int compareTo( Object that )
+    {
+		return ordinal - ( (ReferenceIdentifier) that ).ordinal;
+	}
+
+	public static ReferenceIdentifier getTypeByOrdinal( int type )
+    {
+		for ( int ii = 0; ii < values.length; ii++ )
+			if ( values[ ii ].ordinal == type )
+				return values[ ii ];
+		return LOCL;
+	}
+	
+	public static ReferenceIdentifier getTypeByName( String type )
+    {
+		for ( int ii = 0; ii < values.length; ii++ )
+			if ( values[ ii ].code.equalsIgnoreCase( type ) )
+				return values[ ii ];
+		return LOCL;
+	}
+	
+	public int getOrdinal()
+    {
+		return ordinal;
+	}
+
+	/// PRIVATE /////
+	private final String name;
+	private final String code;
+	private final int    ordinal;
+
+	/**
+	 * Private constructor prevents construction outside of this class.
+	 */
+	private ReferenceIdentifier( int ordinal, String code, String name )
+    {
+        this.ordinal = ordinal;
+        this.code    = code;
+		this.name    = name;
+	}
+
+	/**
+	 * These two lines are all that's necessary to export a List of VALUES.
+	 */
+	private static final ReferenceIdentifier[] values = { INIT, LOCL, PPS, ACTS, USNO, PTB,
TDF,
+			DCF, MSF, WWV, WWVB, WWVH, CHU, LORC, OMEG, GPS, GOES, CDMA };
+	// VALUES needs to be located here, otherwise illegal forward reference
+	public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values )
);
+}
+

Added: incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/StratumType.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/StratumType.java?view=auto&rev=124114
==============================================================================
--- (empty file)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/StratumType.java	Tue
Jan  4 07:41:22 2005
@@ -0,0 +1,89 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.ntp.message;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Stratum: This is a eight-bit unsigned integer indicating the stratum
+ * level of the local clock, with values defined as follows:
+ *
+ *    Stratum  Meaning
+ *    ----------------------------------------------
+ *    0        unspecified or unavailable
+ *    1        primary reference (e.g., radio clock)
+ *    2-15     secondary reference (via NTP or SNTP)
+ *    16-255   reserved
+ */
+public final class StratumType implements Comparable
+{
+	/**
+	 * Enumeration elements are constructed once upon class loading.
+	 * Order of appearance here determines the order of compareTo.
+	 */
+	public static final StratumType UNSPECIFIED         = new StratumType(0, "Unspecified or
unavailable.");
+	public static final StratumType PRIMARY_REFERENCE   = new StratumType(1, "Primary reference.");
+	public static final StratumType SECONDARY_REFERENCE = new StratumType(2, "Secondary reference.");
+	
+	public String toString()
+    {
+		return name;
+	}
+
+	public int compareTo( Object that )
+    {
+		return ordinal - ( (StratumType) that ).ordinal;
+	}
+
+	public static StratumType getTypeByOrdinal( int type )
+    {
+		for ( int ii = 0; ii < values.length; ii++ )
+			if ( values[ ii ].ordinal == type )
+				return values[ ii ];
+		return UNSPECIFIED;
+	}
+	
+	public int getOrdinal()
+    {
+		return ordinal;
+	}
+
+	/// PRIVATE /////
+	private final String name;
+	private final int    ordinal;
+
+	/**
+	 * Private constructor prevents construction outside of this class.
+	 */
+	private StratumType( int ordinal, String name )
+    {
+        this.ordinal = ordinal;
+		this.name    = name;
+	}
+
+	/**
+	 * These two lines are all that's necessary to export a List of VALUES.
+	 */
+	private static final StratumType[] values = { UNSPECIFIED, PRIMARY_REFERENCE,
+			SECONDARY_REFERENCE };
+	// VALUES needs to be located here, otherwise illegal forward reference
+	public static final List VALUES = Collections.unmodifiableList( Arrays.asList( values )
);
+}
+

Mime
View raw message