Class TimesyncExtension
- java.lang.Object
-
- org.cometd.bayeux.server.BayeuxServer.Extension.Adapter
-
- org.cometd.server.ext.TimesyncExtension
-
- All Implemented Interfaces:
org.cometd.bayeux.server.BayeuxServer.Extension
public class TimesyncExtension extends org.cometd.bayeux.server.BayeuxServer.Extension.AdapterTimesync extension (server side).
With each handshake or connect, the extension sends timestamps within the ext field like:
{ext:{timesync:{tc:12345567890,l:23,o:4567},...},...}where:- tc is the client timestamp in ms since 1970 of when the message was sent.
- l is the network lag that the client has calculated.
- o is the clock offset that the client has calculated.
A CometD server that supports timesync, can respond with an ext field like:
{ext:{timesync:{tc:12345567890,ts:1234567900,p:123,a:3},...},...}where:- tc is the client timestamp of when the message was sent,
- ts is the server timestamp of when the message was received
- p is the poll duration in ms - ie the time the server took before sending the response.
- a is the measured accuracy of the calculated offset and lag sent by the client
The relationship between tc, ts, o and l on the server is given by
ts=tc+o+l(the time the server received the message is the client time plus the offset plus the network lag). Thus the accuracy of the o and l settings can be determined witha=tc+o+l-ts.When the client has received the response, it can make a more accurate estimate of the lag as
l2=(now-tc-p)/2(assuming symmetric lag). A new offset can then be calculated with the relationship on the client thatts=tc+o2+l2, thuso2=ts-tc-l2.Since the client also receives the a value calculated on the server, it should be possible to analyse this and compensate for some asymmetry in the lag. But the current client does not do this.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringLAG_ATTRIBUTE
-
Constructor Summary
Constructors Constructor Description TimesyncExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAccuracyTarget()timesync responses are not set if the measured accuracy is less than the accuracyTarget.booleanrcvMeta(org.cometd.bayeux.server.ServerSession from, org.cometd.bayeux.server.ServerMessage.Mutable message)booleansendMeta(org.cometd.bayeux.server.ServerSession session, org.cometd.bayeux.server.ServerMessage.Mutable message)voidsetAccuracyTarget(int target)timesync responses are not set if the measured accuracy is less than the accuracyTarget.
-
-
-
Field Detail
-
LAG_ATTRIBUTE
public static final java.lang.String LAG_ATTRIBUTE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getAccuracyTarget
public int getAccuracyTarget()
timesync responses are not set if the measured accuracy is less than the accuracyTarget.- Returns:
- accuracy target in ms (default 25ms)
-
setAccuracyTarget
public void setAccuracyTarget(int target)
timesync responses are not set if the measured accuracy is less than the accuracyTarget.- Parameters:
target- accuracy target in ms
-
rcvMeta
public boolean rcvMeta(org.cometd.bayeux.server.ServerSession from, org.cometd.bayeux.server.ServerMessage.Mutable message)- Specified by:
rcvMetain interfaceorg.cometd.bayeux.server.BayeuxServer.Extension- Overrides:
rcvMetain classorg.cometd.bayeux.server.BayeuxServer.Extension.Adapter
-
sendMeta
public boolean sendMeta(org.cometd.bayeux.server.ServerSession session, org.cometd.bayeux.server.ServerMessage.Mutable message)- Specified by:
sendMetain interfaceorg.cometd.bayeux.server.BayeuxServer.Extension- Overrides:
sendMetain classorg.cometd.bayeux.server.BayeuxServer.Extension.Adapter
-
-