directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r125037 - in incubator/directory/ntp/trunk/core/src: java/org/apache/ntp/io java/org/apache/ntp/message java/org/apache/ntp/service test/org/apache/ntp
Date Thu, 13 Jan 2005 05:09:48 GMT
Author: erodriguez
Date: Wed Jan 12 21:09:46 2005
New Revision: 125037

URL: http://svn.apache.org/viewcvs?view=rev&rev=125037
Log:
Corrected reference identifier encoding behavior and updated encoder to take injected ByteBuffer.
Modified:
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java
   incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java
   incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java

Modified: incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java?view=diff&rev=125037&p1=incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java&r1=125036&p2=incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java&r2=125037
==============================================================================
--- incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java	(original)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/io/NtpMessageEncoder.java	Wed
Jan 12 21:09:46 2005
@@ -22,31 +22,32 @@
 import org.apache.ntp.message.LeapIndicatorType;
 import org.apache.ntp.message.ModeType;
 import org.apache.ntp.message.NtpMessage;
+import org.apache.ntp.message.ReferenceIdentifier;
 
 
 public class NtpMessageEncoder
 {
-	public ByteBuffer encode( NtpMessage message )
+	public void encode( ByteBuffer byteBuffer, NtpMessage message )
 	{
-		ByteBuffer buffer = ByteBuffer.allocate( 576 );
-		
 		byte header = 0x00;
 		header = encodeLeapIndicator( message.getLeapIndicator(), header );
 		header = encodeVersionNumber( message.getVersionNumber(), header );
 		header = encodeMode( message.getMode(), header );
-		buffer.put( header );
+		byteBuffer.put( header );
 		
-		buffer.put( (byte)( message.getStratum().getOrdinal() & 0xFF ) );
-		buffer.put( (byte)( message.getPollInterval() & 0xFF ) );
-		buffer.put( (byte)( message.getPrecision() & 0xFF ) );
+		byteBuffer.put( (byte)( message.getStratum().getOrdinal() & 0xFF ) );
+		byteBuffer.put( (byte)( message.getPollInterval() & 0xFF ) );
+		byteBuffer.put( (byte)( message.getPrecision() & 0xFF ) );
 		
-		buffer.putInt( message.getRootDelay() );
-		buffer.putInt( message.getRootDispersion() );
-		buffer.putInt( message.getReferenceIdentifier().getOrdinal() );
+		byteBuffer.putInt( message.getRootDelay() );
+		byteBuffer.putInt( message.getRootDispersion() );
 		
-		buffer.rewind();
+		encodeReferenceIdentifier( message.getReferenceIdentifier(), byteBuffer );
 		
-		return buffer;
+		message.getReferenceTimestamp().writeTo( byteBuffer );
+		message.getOriginateTimestamp().writeTo( byteBuffer );
+		message.getReceiveTimestamp().writeTo( byteBuffer );
+		message.getTransmitTimestamp().writeTo( byteBuffer );
 	}
 	
 	private byte encodeLeapIndicator( LeapIndicatorType leapIndicator, byte header )
@@ -65,6 +66,16 @@
 	{
 		byte threeBits = (byte)( mode.getOrdinal() & 0x07 );
 		return (byte)( threeBits | header );
+	}
+	
+	private void encodeReferenceIdentifier( ReferenceIdentifier identifier, ByteBuffer byteBuffer
)
+	{
+		char[] characters = identifier.getCode().toCharArray();
+		
+		for ( int ii = 0; ii < characters.length; ii++ )
+		{
+			byteBuffer.put( (byte)characters[ ii ] );
+		}
 	}
 }
 

Modified: 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=diff&rev=125037&p1=incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java&r1=125036&p2=incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java&r2=125037
==============================================================================
--- incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java
(original)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/message/ReferenceIdentifier.java
Wed Jan 12 21:09:46 2005
@@ -90,7 +90,12 @@
     {
 		return ordinal;
 	}
-
+	
+	public String getCode()
+	{
+		return code;
+	}
+	
 	/// PRIVATE /////
 	private final String name;
 	private final String code;

Modified: incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java?view=diff&rev=125037&p1=incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java&r1=125036&p2=incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java&r2=125037
==============================================================================
--- incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java
(original)
+++ incubator/directory/ntp/trunk/core/src/java/org/apache/ntp/service/NtpServiceImpl.java
Wed Jan 12 21:09:46 2005
@@ -36,9 +36,9 @@
 		modifier.setLeapIndicator( LeapIndicatorType.NO_WARNING );
 		modifier.setVersionNumber( 4 );
 		modifier.setMode( ModeType.SERVER );
-		modifier.setStratum( StratumType.SECONDARY_REFERENCE );
-		modifier.setPollInterval( (byte)0x40 );
-		modifier.setPrecision( (byte)0xEC );
+		modifier.setStratum( StratumType.PRIMARY_REFERENCE );
+		modifier.setPollInterval( (byte)0x04 );
+		modifier.setPrecision( (byte)0xFA );
 		modifier.setRootDelay( 0 );
 		modifier.setRootDispersion( 0 );
 		modifier.setReferenceIdentifier( ReferenceIdentifier.LOCL );

Modified: incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java?view=diff&rev=125037&p1=incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java&r1=125036&p2=incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java&r2=125037
==============================================================================
--- incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java
(original)
+++ incubator/directory/ntp/trunk/core/src/test/org/apache/ntp/NtpMessageEncoderTest.java
Wed Jan 12 21:09:46 2005
@@ -34,8 +34,6 @@
 {
 	public void testEncodeMessage() throws Exception
 	{
-		ByteBuffer replyByteBuffer;
-		
 		NtpMessageModifier modifier = new NtpMessageModifier();
 		modifier.setLeapIndicator( LeapIndicatorType.NO_WARNING );
 		modifier.setVersionNumber( 4 );
@@ -56,13 +54,15 @@
 		
 		NtpMessage message = modifier.getNtpMessage();
 		
+		ByteBuffer replyByteBuffer = ByteBuffer.allocate( 1024 );
+		
 		NtpMessageEncoder encoder = new NtpMessageEncoder();
-		replyByteBuffer = encoder.encode( message );
+		encoder.encode( replyByteBuffer, message );
 		
 		print( message );
 		
 		NtpMessageDecoder decoder = new NtpMessageDecoder();
-		NtpMessage reply          = decoder.decode( replyByteBuffer );
+		NtpMessage reply = decoder.decode( replyByteBuffer );
 		
 		print( reply );
 	}

Mime
View raw message