public class SyncClock extends java.lang.Object implements MultiPeerListener
This class acts as time-server or time-client. The "SyncronizationThread" send "0L" messages periodically to the chosen server in order to get the server time stamp and measure the round trip time. The "0L" message is answered directly inside the "OnMessage" method (acting in the server side).
Because the related "MultiPeer" is provided in construction time, the newly created object registers itself as MultiPeer "Specific Listener".
The period of synchronization is shorter during startup or when the correcting offset exceeds the limit value, getting slower during normal operation.
Modifier and Type | Class and Description |
---|---|
private class |
SyncClock.SynchronizationThread |
static class |
SyncClock.SyncSample
Auxiliary class to store the sync tries results.
|
Modifier and Type | Field and Description |
---|---|
private static int |
maxAllowedOffset |
private int |
messagePeriod |
private static int |
messagePeriodMAX |
private static int |
messagePeriodMIN |
private boolean |
messageReady |
private MultiPeer |
netPeers |
private long |
tRecv |
private long |
tSend |
private long |
tServer |
Modifier and Type | Method and Description |
---|---|
void |
onMessage(Message m)
MultiPeerListener callback.
|
void |
onNewConnection(Destination dest)
MultiPeerListener callback.
|
private void |
waitForServerResponse()
Used in "SynchronizationThread" to wait until the time server response.
|
private static int maxAllowedOffset
private int messagePeriod
private static int messagePeriodMAX
private static int messagePeriodMIN
private boolean messageReady
private MultiPeer netPeers
private long tRecv
private long tSend
private long tServer
public SyncClock(MultiPeer mp)
mp
- public void onMessage(Message m)
onMessage
in interface MultiPeerListener
public void onNewConnection(Destination dest)
onNewConnection
in interface MultiPeerListener
private void waitForServerResponse()