cgl.narada.service.time.ntptime
Class NtpConnection

java.lang.Object
  extended by cgl.narada.service.time.ntptime.NtpConnection

public class NtpConnection
extends Object

This class provides some methods to make UDP connection, send/receive NTP packets


Field Summary
static int defaultNtpPort
           
 
Constructor Summary
NtpConnection(InetAddress iaddr)
          Generates a UDP connection and sets the timeout to the default timeout value.
NtpConnection(InetAddress iaddr, int iport)
          Generates a UDP connection and sets timeout to the socket
 
Method Summary
 void close()
          Closes the connection.
 NtpInfo getInfo()
          Exchanges NtpDatagramPacket with the server and generates NtpInfo object.
 int getTimeout()
          Gets the timeout of the connection.
 NtpInfo getTSInfo()
          This method is intended to be used with ClientDiscrepancy class.
 void receive(NtpDatagramPacket ntpDatagramPacket)
          Waits for a reply from the server.
 void receiveTS(NtpDatagramPacket ntpDatagramPacket, long offset11)
          This method is intended to be used with ClientDiscrepancy class.
 void send(NtpDatagramPacket ntpDatagramPacket)
          Sends NtpDatagramPacket to the server.
 void setBuffer(int start, int end, byte[] tbuffer, byte[] data)
          Sets buffer entries from start to end-1 with the given data array
 void setTimeout(int timeout)
          Sets the timeout of the asociated connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultNtpPort

public static final int defaultNtpPort
See Also:
Constant Field Values
Constructor Detail

NtpConnection

public NtpConnection(InetAddress iaddr,
                     int iport)
              throws SocketException
Generates a UDP connection and sets timeout to the socket

Parameters:
iaddr - InetAddress - InetAddress of the server
iport - int - port number of the server
Throws:
SocketException - - SocketException is thrown in case of failure

NtpConnection

public NtpConnection(InetAddress iaddr)
              throws SocketException
Generates a UDP connection and sets the timeout to the default timeout value.

Parameters:
iaddr - InetAddress - InetAddress of the server
Throws:
SocketException - - SocketException is thrown in case of failure
Method Detail

setBuffer

public void setBuffer(int start,
                      int end,
                      byte[] tbuffer,
                      byte[] data)
Sets buffer entries from start to end-1 with the given data array

Parameters:
start - int - start value
end - int - end value
tbuffer - byte[] - buffer
data - byte[] - data array to be copied

getInfo

public NtpInfo getInfo()
                throws IOException
Exchanges NtpDatagramPacket with the server and generates NtpInfo object.

Returns:
NtpInfo - NtpInfo object obtained from NTPDatagramPacket
Throws:
IOException - - IOException is thrown in case of socket timeout or connection failure

getTSInfo

public NtpInfo getTSInfo()
                  throws IOException
This method is intended to be used with ClientDiscrepancy class. Please do not use for other purposes. Returns NtpInfo.

Returns:
NtpInfo
Throws:
IOException

setTimeout

public void setTimeout(int timeout)
                throws SocketException
Sets the timeout of the asociated connection.

Parameters:
timeout - int - value of the timeout
Throws:
SocketException - - SocketException is thrown in case of connection failure

getTimeout

public int getTimeout()
Gets the timeout of the connection. The default timeout is 500 ms.

Returns:
int - timeout value

close

public void close()
Closes the connection.


receive

public void receive(NtpDatagramPacket ntpDatagramPacket)
             throws IOException
Waits for a reply from the server.

Parameters:
ntpDatagramPacket - NtpDatagramPacket - NtpDatagramPacket that will be set to the NtpDatagramPacket received from the server.
Throws:
IOException - - IOException is thrown in case of socket timeout or connection failure

receiveTS

public void receiveTS(NtpDatagramPacket ntpDatagramPacket,
                      long offset11)
               throws IOException
This method is intended to be used with ClientDiscrepancy class. Please do not use for other purposes. Receives NtpDatagramPacket and timestamps it with the adjusted time value.

Parameters:
ntpDatagramPacket -
offset11 - long - offset
Throws:
IOException

send

public void send(NtpDatagramPacket ntpDatagramPacket)
          throws IOException
Sends NtpDatagramPacket to the server.

Parameters:
ntpDatagramPacket - NtpDatagramPacket - NtpDatagramPacket that will be sent to the server.
Throws:
IOException - - IOException is thrown in case of connection failure


For comments and suggestions please send e-mail to The NaradaBrokering Project