com.atlassian.confluence.core.datetime
Class RequestTimeThreadLocal

java.lang.Object
  extended by com.atlassian.confluence.core.datetime.RequestTimeThreadLocal

public class RequestTimeThreadLocal
extends Object

A thread-local for storing the time a request was received. This timestamp can be used for consistent date-time handling across all operations performed within the scope of a single request.

Since:
2.7

Constructor Summary
RequestTimeThreadLocal()
           
 
Method Summary
static void clearTime()
          Clears the stored value of the thread-local.
static long getTime()
          Retrieves the value of the request time thread-local.
static Date getTimeOrNow()
          Returns the value of the request time thread-local converted to a new Date object.
static void setTime(long currentTimeMillis)
          Sets the value of the thread-local.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestTimeThreadLocal

public RequestTimeThreadLocal()
Method Detail

setTime

public static void setTime(long currentTimeMillis)
Sets the value of the thread-local. Should not be called by application code, but rather by a servlet filter which handles each request.

Parameters:
currentTimeMillis - the timestamp to store, measured in milliseconds since the epoch defined by Date.Date(long).

clearTime

public static void clearTime()
Clears the stored value of the thread-local. Should not be called by application code, but rather by the finally block in the servlet filter which calls setTime(long).


getTime

public static long getTime()
Retrieves the value of the request time thread-local. The value is measured in milliseconds since the epoch defined by Date.Date(long).

Returns:
the value of the request time thread-local, or -1 if it has not been set.

getTimeOrNow

public static Date getTimeOrNow()
Returns the value of the request time thread-local converted to a new Date object. If the thread-local is not set, returns a new Date representing the current time.

Returns:
a Date with the time stored in the thread-local, or the a new Date with the current time if the thread-local is not set.


Copyright © 2003-2013 Atlassian. All Rights Reserved.