com.threerings.presents.data
Class TimeBaseObject

java.lang.Object
  extended by com.threerings.presents.dobj.DObject
      extended by com.threerings.presents.data.TimeBaseObject
All Implemented Interfaces:
Streamable

public class TimeBaseObject
extends DObject

Used to communicate time bases to clients so that more efficient delta times can be transmitted over the network. Two time stamps are maintained: even and odd. When the even time base is sufficiently old that our delta time container (usually a short or an int) will exceed its maximum value, we switch to the odd time base. The bouncing between two separate values prevents problems from arising when the base time is changed, yet values using the old base time might still be propagating through the system.

Note that for sufficiently small delta time containers, stale values could still linger longer than the time required for two swaps (two byte delta stamps for example, must swap every 30 seconds).


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.threerings.io.Streamable
Streamable.Closure
 
Field Summary
static String EVEN_BASE
          The field name of the evenBase field.
 long evenBase
          The even time base, used to decode even delta times.
static String ODD_BASE
          The field name of the oddBase field.
 long oddBase
          The odd time base, used to decode odd delta times.
 
Fields inherited from class com.threerings.presents.dobj.DObject
_accessors, _atable, _controller, _deathWish, _listeners, _locattrs, _locks, _oid, _omgr, _scount, _subs, _tcancelled, _tcount, _tevent
 
Constructor Summary
TimeBaseObject()
           
 
Method Summary
 long fromDelta(int delta)
          Converts the supplied delta time back to a wall time based on the base time in this time base object.
protected  long getDelta(long timeStamp, long maxValue)
          Obtains a delta with the specified maximum value, swapping from even to odd, if necessary.
 void setEvenBase(long value)
          Requests that the evenBase field be set to the specified value.
 void setOddBase(long value)
          Requests that the oddBase field be set to the specified value.
 int toIntDelta(long timeStamp)
          Converts the supplied time stamp into a time delta (measured relative to the appropriate time base, even or odd) with maximum value of 2^31.
 short toShortDelta(long timeStamp)
          Converts the supplied time stamp into a time delta (measured relative to the appropriate time base, even or odd) with maximum value of 2^15.
 
Methods inherited from class com.threerings.presents.dobj.DObject
acquireLock, addListener, addListener, addSubscriber, addToSet, cancelTransaction, changeAttribute, checkPermissions, checkPermissions, clearLock, clearTransaction, commitTransaction, createAccessors, destroy, getAccessController, getAccessor, getAttribute, getListenerIndex, getLocal, getLocals, getManager, getOid, getSet, inTransaction, isActive, isAuthoritative, notifyListeners, notifyProxies, postEvent, postMessage, postMessage, releaseLock, removeFromSet, removeListener, removeSubscriber, requestAttributeChange, requestAttributeChange, requestElementUpdate, requestElementUpdate, requestEntryAdd, requestEntryRemove, requestEntryUpdate, requestEntryUpdate, requestOidAdd, requestOidAdd, requestOidRemove, requestOidRemove, setAccessController, setAttribute, setDestroyOnLastSubscriberRemoved, setLocal, setManager, setOid, startTransaction, toString, toString, updateSet, which, which
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVEN_BASE

@Generated(value="com.threerings.presents.tools.GenDObjectTask")
public static final String EVEN_BASE
The field name of the evenBase field.

See Also:
Constant Field Values

ODD_BASE

@Generated(value="com.threerings.presents.tools.GenDObjectTask")
public static final String ODD_BASE
The field name of the oddBase field.

See Also:
Constant Field Values

evenBase

public long evenBase
The even time base, used to decode even delta times.


oddBase

public long oddBase
The odd time base, used to decode odd delta times.

Constructor Detail

TimeBaseObject

public TimeBaseObject()
Method Detail

toShortDelta

public short toShortDelta(long timeStamp)
Converts the supplied time stamp into a time delta (measured relative to the appropriate time base, even or odd) with maximum value of 2^15. (One bit must be used to indicate that it is an even or odd time stamp).


toIntDelta

public int toIntDelta(long timeStamp)
Converts the supplied time stamp into a time delta (measured relative to the appropriate time base, even or odd) with maximum value of 2^31. (One bit must be used to indicate that it is an even or odd time stamp).


fromDelta

public long fromDelta(int delta)
Converts the supplied delta time back to a wall time based on the base time in this time base object. Either an int or short delta can be passed to this method (the short will have been promoted to an int in the process but that will not mess up its encoded value).


getDelta

protected long getDelta(long timeStamp,
                        long maxValue)
Obtains a delta with the specified maximum value, swapping from even to odd, if necessary.


setEvenBase

@Generated(value="com.threerings.presents.tools.GenDObjectTask")
public void setEvenBase(long value)
Requests that the evenBase field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.


setOddBase

@Generated(value="com.threerings.presents.tools.GenDObjectTask")
public void setOddBase(long value)
Requests that the oddBase field be set to the specified value. The local value will be updated immediately and an event will be propagated through the system to notify all listeners that the attribute did change. Proxied copies of this object (on clients) will apply the value change when they received the attribute changed notification.