com.bigdata.util
Class MillisecondTimestampFactory

java.lang.Object
  extended by com.bigdata.util.MillisecondTimestampFactory

public class MillisecondTimestampFactory
extends Object

A timestamp factory based on System.currentTimeMillis(). Timestamps reported by this factory are guarenteed to be distinct and strictly increasing during the life cycle of the JVM. No guarentee is made if across JVMs or system reboots. A means is available to inform the factory of the earliest timestamp that it may serve. This may be used on restart to ensure that time goes forward or when handing off from one timestamp service to another.

Note: Time as reported by System.currentTimeMillis() can do crazy things, including going backwards - presumably because of an error somewhere in the time management stack (observed on Fedora core 6 with Sun JDK 1.6.0_03). In these cases a warning is logged and the timestamp factory begins to assign up one long integers instead. If time catches up, then another warning is logged and the factory again begins to report timestamps based on System.currentTimeMillis(). Note that when the factory is using a one-up assignment it may appear to have a resolution finer than one millisecond.

Note: method on this class are synchronized to ensure that concurrent callers receive distinct timestamps. Likewise, the methods on this class are static to ensure that assigned timestamps are global for a JVM.

Version:
$Id: MillisecondTimestampFactory.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected static org.apache.log4j.Logger log
           
 
Method Summary
static boolean isAutoIncMode()
          Return true if the timestamp factory is in auto-increment mode.
static long nextMillis()
          Generates a timestamp based on System.currentTimeMillis() that is guaranteed to be distinct from the last timestamp generated by this method during the life cycle of the JVM.
static void setLowerBound(long lowerBound)
          Sets the lower bound for the generated timestamps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Method Detail

isAutoIncMode

public static boolean isAutoIncMode()
Return true if the timestamp factory is in auto-increment mode.


setLowerBound

public static void setLowerBound(long lowerBound)
Sets the lower bound for the generated timestamps. This method may be used to safely synchronize a failover timestamp service with a primary. Extreme care should be used with this method as it can force the factory to return timestamps out of order.

Parameters:
lowerBound - The lower bound.
Throws:
IllegalArgumentException - if the given timestamp is non-positive.

nextMillis

public static long nextMillis()
Generates a timestamp based on System.currentTimeMillis() that is guaranteed to be distinct from the last timestamp generated by this method during the life cycle of the JVM. No guarantee is made if across JVMs or system reboots. However, a means is available to inform the factory of the earliest timestamp that it may serve.

Returns:
A timestamp with no more millisecond resolution.
See Also:
System.currentTimeMillis()


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.