org.jboss.ha.timestamp
Class TimestampDiscrepancy

java.lang.Object
  extended by org.jboss.ha.timestamp.TimestampDiscrepancy
All Implemented Interfaces:
Serializable

public class TimestampDiscrepancy
extends Object
implements Serializable

Provides information on possible system timestamp discrepancies between a remote node and the local node.

Usage: The local node should record the current system time and then request the current system time from the remote node. The local node should then record the current system time when the response is received from the remote node. The three values are then passed to this class' constructor.

Version:
$Revision: $
Author:
Brian Stansberry
See Also:
Serialized Form

Field Summary
static TimestampDiscrepancy NO_DISCREPANCY
          Fake discrepancy that indicates no system clock difference
 
Constructor Summary
TimestampDiscrepancy(long remoteTimestamp, long requestSent, long responseReceived)
          Create a new TimestampDiscrepancy using the value returned by a remote request plus the local timestamps for when the request started and completed.
TimestampDiscrepancy(TimestampDiscrepancy base, TimestampDiscrepancy intermediary)
          Generates a synthetic TimestampDiscrepancy based on a value provided by another node adjusted for the discrepancy between this node and the private TimestampDiscrepancy(long now) { this(now, now, now); } node that provided the base value.
 
Method Summary
 long getAbsoluteMaxDiscrepancy()
          Gets the higher of the absolute value of getMinDiscrepancy() or the absolute value of getMaxDiscrepancy().
 long getDiscrepancyRange()
          Gets the difference between getMinDiscrepancy() and getMaxDiscrepancy()
 long getEstimatedDiscrepancy()
          Gets a rough estimate of the timestamp discrepancy between the systems.
 long getMaxDiscrepancy()
          Maximum offset that would be applied to a remote timestamp to obtain the timestamp on the local system of a simultaneously occurring event.
 long getMaxLocalTimestamp(long remoteTimestamp)
          Gets the maximum value for a local timestamp that would correspond to the remote timestamp.
 long getMaxRemoteTimestamp(long localTimestamp)
          Gets the maximum value for a remote timestamp that would correspond to the local timestamp.
 long getMinDiscrepancy()
          Minimum offset that would be applied to a local timestamp to obtain the timestamp on the remote system of a simultaneously occurring event.
 long getMinLocalTimestamp(long remoteTimestamp)
          Gets the minimum value for a local timestamp that would correspond to the remote timestamp.
 long getMinRemoteTimestamp(long localTimestamp)
          Gets the minimum value for a remote timestamp that would correspond to the local timestamp.
 long getRemoteTimestamp()
          Gets the timestamp that the remote node returned.
 long getRequestRoundtripTime()
          Gets the number of ms it took for the remote request that returned the remote timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_DISCREPANCY

public static final TimestampDiscrepancy NO_DISCREPANCY
Fake discrepancy that indicates no system clock difference

Constructor Detail

TimestampDiscrepancy

public TimestampDiscrepancy(long remoteTimestamp,
                            long requestSent,
                            long responseReceived)
Create a new TimestampDiscrepancy using the value returned by a remote request plus the local timestamps for when the request started and completed.

Parameters:
remoteTimestamp - the timestamp returned by the remote node
requestSent - local timestamp immediately before the timestamp request was made
responseReceived - local timestamp immediately after receipt of response to the timestamp request

TimestampDiscrepancy

public TimestampDiscrepancy(TimestampDiscrepancy base,
                            TimestampDiscrepancy intermediary)
Generates a synthetic TimestampDiscrepancy based on a value provided by another node adjusted for the discrepancy between this node and the private TimestampDiscrepancy(long now) { this(now, now, now); } node that provided the base value. Used to create an estimated discrepancy between this node and a node that can no longer be contacted directly (e.g. because it has shut down). Necessarily less accurate than a TimestampDiscrepancy constructed via the normal method.

Parameters:
base -
intermediary -
Method Detail

getRemoteTimestamp

public long getRemoteTimestamp()
Gets the timestamp that the remote node returned.

Returns:
the remote timestamp.

getMinDiscrepancy

public long getMinDiscrepancy()
Minimum offset that would be applied to a local timestamp to obtain the timestamp on the remote system of a simultaneously occurring event.

Returns:
the minimum discrepancy

getMaxDiscrepancy

public long getMaxDiscrepancy()
Maximum offset that would be applied to a remote timestamp to obtain the timestamp on the local system of a simultaneously occurring event.

Returns:
the maximum discrepancy

getAbsoluteMaxDiscrepancy

public long getAbsoluteMaxDiscrepancy()
Gets the higher of the absolute value of getMinDiscrepancy() or the absolute value of getMaxDiscrepancy().


getDiscrepancyRange

public long getDiscrepancyRange()
Gets the difference between getMinDiscrepancy() and getMaxDiscrepancy()

Returns:

getEstimatedDiscrepancy

public long getEstimatedDiscrepancy()
Gets a rough estimate of the timestamp discrepancy between the systems.

Returns:
the average between getMinDiscrepancy() and getMaxDiscrepancy()

getRequestRoundtripTime

public long getRequestRoundtripTime()
Gets the number of ms it took for the remote request that returned the remote timestamp. The longer the request took to execute, the less accurate the timestamp discrepancy.

Returns:
number of ms it took to execute the timestamp request

getMinLocalTimestamp

public long getMinLocalTimestamp(long remoteTimestamp)
Gets the minimum value for a local timestamp that would correspond to the remote timestamp.

Parameters:
remoteTimestamp - the remote timestamp
Returns:
the equivalent local timestamp

getMaxLocalTimestamp

public long getMaxLocalTimestamp(long remoteTimestamp)
Gets the maximum value for a local timestamp that would correspond to the remote timestamp.

Parameters:
remoteTimestamp - the remote timestamp
Returns:
the equivalent local timestamp

getMinRemoteTimestamp

public long getMinRemoteTimestamp(long localTimestamp)
Gets the minimum value for a remote timestamp that would correspond to the local timestamp.

Parameters:
localTimestamp - the local timestamp
Returns:
the equivalent remote timestamp

getMaxRemoteTimestamp

public long getMaxRemoteTimestamp(long localTimestamp)
Gets the maximum value for a remote timestamp that would correspond to the local timestamp.

Parameters:
localTimestamp - the local timestamp
Returns:
the equivalent remote timestamp


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.