org.ccnx.ccn.protocol.CCNTime Class Reference

CCN has a time representation for versions and signing times that is quantized at a granularity of 2^-12 seconds (approximately 1/4 msec). More...

Inherits java::sql::Timestamp.

List of all members.

Public Member Functions

 CCNTime (long msec)
 Create a CCNTime.
 CCNTime (Timestamp timestamp)
 Create a CCNTime.
 CCNTime (Date time)
 Create a CCNTime.
 CCNTime (byte[] binaryTime12)
 Create a CCNTime from its binary encoding.
 CCNTime ()
 Creates a CCNTime initialized to the current time.
byte[] toBinaryTime ()
 Generate the binary representation of a CCNTime.
long toBinaryTimeAsLong ()
 Generate the internal long representation of a CCNTime, useful for comparisons and used internally.
void setTime (long msec)
void setNanos (int nanos)
void addNanos (int nanos)
 Note: you have to use a relatively high value of nanos before you get across a quantization unit and have an impact.
void increment (int timeUnits)
 A helper method to increment to avoid collisions.
boolean equals (Timestamp ts)
 We handle all comparison functions by quantizing the thing we are being compared to, then comparing.
int compareTo (Date o)
int compareTo (Timestamp ts)
boolean before (Timestamp ts)
boolean after (Timestamp ts)
boolean before (Date when)
boolean after (Date when)
String toShortString ()
 Generate a string representation of a CCNTime containing only date and HH:MM:SS, not milliseconds or nanoseconds.

Static Public Member Functions

static CCNTime fromBinaryTimeAsLong (long binaryTimeAsLong)
 Factory method to generate a CCNTime from our internal long time representation.
static long toBinaryTimeAsLong (long msec, long nanos)
 Static method to convert from milliseconds and nanoseconds to our internal long representation.
static CCNTime now ()
 Create a CCNTime initialized to the current date/time.

Static Public Attributes

static final int NANOS_MAX = 999877929
 This is the highest nanos value that doesn't quantize to over the ns limit for Timestamp of 999999999.

Protected Member Functions

 CCNTime (long msec, long nanos)
 Creates a CCNTime from a specification of msec and nanos, to ease implementing compatibility with Timestamp and Date.
 CCNTime (long binaryTimeAsLong, boolean unused)
 Creates a CCNTime from the internal long representation of the quantized time.
void setFromBinaryTimeAsLong (long binaryTimeAsLong)


Detailed Description

CCN has a time representation for versions and signing times that is quantized at a granularity of 2^-12 seconds (approximately 1/4 msec).

Because it does not quantize time evenly on millisecond boundaries, this can lead to confusion -- t = System.currentTimeMillis(), when used to set a version v, for example, then ends up with v != t as v is quantized and t isn't. Simply providing quantization utility routines to help developers turned out to be error-prone. So we are moving all uses of time in CCN to pre-quantized CCNTime objects, which encapsulates CCN time quantization (which could change), and gives developers ways to deal with it without having to think about it.

CCNTime, all though it implements methods like getNanos, only represents time with a granularity equal to the underlying CCN wire format -- i.e. ~.25 msec.


Constructor & Destructor Documentation

org.ccnx.ccn.protocol.CCNTime.CCNTime ( long  msec  ) 

Create a CCNTime.

Parameters:
msec time in msec

org.ccnx.ccn.protocol.CCNTime.CCNTime ( Timestamp  timestamp  ) 

Create a CCNTime.

Parameters:
timestamp source timestamp to initialize from, some precision will be lost

org.ccnx.ccn.protocol.CCNTime.CCNTime ( Date  time  ) 

Create a CCNTime.

Parameters:
time source Date to initialize from, some precision will be lost as CCNTime does not round to unitary milliseconds

org.ccnx.ccn.protocol.CCNTime.CCNTime ( byte[]  binaryTime12  ) 

Create a CCNTime from its binary encoding.

Parameters:
binaryTime12 the binary representation of a CCNTime

org.ccnx.ccn.protocol.CCNTime.CCNTime ( long  msec,
long  nanos 
) [protected]

Creates a CCNTime from a specification of msec and nanos, to ease implementing compatibility with Timestamp and Date.

Note that there is redundant data here -- the last 3 significant digits of msec are also represented as the top 3 of nanos. We take the version in the nanos. This is derived from Java's slightly odd Timestamp handling.

Parameters:
msec milliseconds
nanos nanoseconds

org.ccnx.ccn.protocol.CCNTime.CCNTime ( long  binaryTimeAsLong,
boolean  unused 
) [protected]

Creates a CCNTime from the internal long representation of the quantized time.

Equivalent to setFromBinaryTimeAsLong.

Parameters:
binaryTimeAsLong the time in our internal units
unused a marker parameter to separate this from another constructor


Member Function Documentation

static CCNTime org.ccnx.ccn.protocol.CCNTime.fromBinaryTimeAsLong ( long  binaryTimeAsLong  )  [static]

Factory method to generate a CCNTime from our internal long time representation.

Make this a static method to avoid confusion; should be little used

Returns:

byte [] org.ccnx.ccn.protocol.CCNTime.toBinaryTime (  ) 

Generate the binary representation of a CCNTime.

Returns:
the binary representation we use for encoding

long org.ccnx.ccn.protocol.CCNTime.toBinaryTimeAsLong (  ) 

Generate the internal long representation of a CCNTime, useful for comparisons and used internally.

Returns:
the long representation of this time in our internal units

static long org.ccnx.ccn.protocol.CCNTime.toBinaryTimeAsLong ( long  msec,
long  nanos 
) [static]

Static method to convert from milliseconds and nanoseconds to our internal long representation.

Assumes that nanos also contains the integral milliseconds for this time. Ignores msec component in msec.

Parameters:
msec milliseconds
nanos nanoseconds
Returns:

void org.ccnx.ccn.protocol.CCNTime.addNanos ( int  nanos  ) 

Note: you have to use a relatively high value of nanos before you get across a quantization unit and have an impact.

Our units are 2^-12 seconds, or ~250 msec. So 250000 nanos.

Parameters:
nanos 

void org.ccnx.ccn.protocol.CCNTime.increment ( int  timeUnits  ) 

A helper method to increment to avoid collisions.

Add a number of CCNx quantized time units to the time. Synchronize if modifications can be performed from multiple threads.

boolean org.ccnx.ccn.protocol.CCNTime.equals ( Timestamp  ts  ) 

We handle all comparison functions by quantizing the thing we are being compared to, then comparing.

The only thing this won't catch is if a normal Timestamp or Date's comparison method is called with a CCNTime as an argument. This is a small risk, and worth it given the convenience of subclassing Timestamp and using it for most functionality.

static CCNTime org.ccnx.ccn.protocol.CCNTime.now (  )  [static]

Create a CCNTime initialized to the current date/time.

Returns:
the new CCNTime


The documentation for this class was generated from the following file:

Generated on Thu Feb 16 00:45:06 2012 for Content-Centric Networking in Java by  doxygen 1.5.6