org.opends.server.util
Class TimeThread

java.lang.Object
  extended by java.lang.Thread
      extended by org.opends.server.api.DirectoryThread
          extended by org.opends.server.util.TimeThread
All Implemented Interfaces:
java.lang.Runnable

@PublicAPI(stability=UNCOMMITTED,
           mayInstantiate=false,
           mayExtend=false,
           mayInvoke=true)
public final class TimeThread
extends DirectoryThread

This class defines a thread that will wake up periodically, get the current time, and store various representations of it. Note that only limited debugging will be performed in this class due to the frequency with which it will be called.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
static java.util.Calendar getCalendar()
          Retrieves a Calendar containing the time at the last update.
static java.util.Date getDate()
          Retrieves a Date containing the time at the last update.
static java.lang.String getGeneralizedTime()
          Retrieves a string containing a normalized representation of the current time in a generalized time format.
static java.lang.String getGMTTime()
          Retrieves a string containing the current time in GMT.
static int getHourAndMinute()
          Retrieves an integer containing the time in HHmm format at the last update.
static java.lang.String getLocalTime()
          Retrieves a string containing the current time in the local time zone.
static long getNanoTime()
          Retrieves the time in nanoseconds from the most precise available system timer.
static long getTime()
          Retrieves the time in milliseconds since the epoch at the last update.
static java.lang.String getUserDefinedTime(java.lang.String formatString)
          Retrieves the current time formatted using the given format string.
static void removeUserDefinedFormatter(java.lang.String formatString)
          Removes the user-defined time formatter from this time thread so that it will no longer be maintained.
 void run()
          Operates in a loop, getting the current time and then sleeping briefly before checking again.
 
Methods inherited from class org.opends.server.api.DirectoryThread
getAssociatedTask, getCreationStackTrace, getDebugProperties, getParentThread, setAssociatedTask
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

run

public void run()
Operates in a loop, getting the current time and then sleeping briefly before checking again.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getCalendar

public static java.util.Calendar getCalendar()
Retrieves a Calendar containing the time at the last update.

Returns:
A Calendar containing the time at the last update.

getDate

public static java.util.Date getDate()
Retrieves a Date containing the time at the last update.

Returns:
A Date containing the time at the last update.

getTime

public static long getTime()
Retrieves the time in milliseconds since the epoch at the last update.

Returns:
The time in milliseconds since the epoch at the last update.

getNanoTime

public static long getNanoTime()
Retrieves the time in nanoseconds from the most precise available system timer. The value retured represents nanoseconds since some fixed but arbitrary time.

Returns:
The time in nanoseconds from some fixed but arbitrary time.

getGeneralizedTime

public static java.lang.String getGeneralizedTime()
Retrieves a string containing a normalized representation of the current time in a generalized time format. The timestamp will look like "20050101000000.000Z".

Returns:
A string containing a normalized representation of the current time in a generalized time format.

getLocalTime

public static java.lang.String getLocalTime()
Retrieves a string containing the current time in the local time zone. The timestamp format will look like "01/Jan/2005:00:00:00 -0600".

Returns:
A string containing the current time in the local time zone.

getGMTTime

public static java.lang.String getGMTTime()
Retrieves a string containing the current time in GMT. The timestamp will look like "20050101000000Z".

Returns:
A string containing the current time in GMT.

getHourAndMinute

public static int getHourAndMinute()
Retrieves an integer containing the time in HHmm format at the last update. It will be calculated as "(hourOfDay*100) + minuteOfHour".

Returns:
An integer containing the time in HHmm format at the last update.

getUserDefinedTime

public static java.lang.String getUserDefinedTime(java.lang.String formatString)
                                           throws java.lang.IllegalArgumentException
Retrieves the current time formatted using the given format string. The first time this method is used with a given format string, it will be used to create a formatter that will generate the time string. That formatter will then be put into a list so that it will be maintained automatically for future use.

Parameters:
formatString - The string that defines the format of the time string to retrieve.
Returns:
The formatted time string.
Throws:
java.lang.IllegalArgumentException - If the provided format string is invalid.

removeUserDefinedFormatter

public static void removeUserDefinedFormatter(java.lang.String formatString)
Removes the user-defined time formatter from this time thread so that it will no longer be maintained. This is a safe operation because if the same format string is used for multiple purposes then it will be added back the next time a time is requested with the given format.

Parameters:
formatString - The format string for the date formatter to remove.