atg.service.util
Class ChunkedTimeInterval

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.util.ChunkedTimeInterval
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class ChunkedTimeInterval
extends GenericService

A component that provides a consistent window (chunk) of time for any time value within that window. For example, if configured with a time window size of 3 hours (intervalCount of 3 and an intervalUnitName of "hours"), this component will calculate the same start and end time for any time value within that period.

This is useful for providing a degree of time granularity when data is cached. It can be used to avoid the problem of filling the cache with time values that will never repeat.

The names of the available interval type are, "second", "minute", "hour", "day", "week", "month" and "year". They may be specified with their plural forms as well (e.g "minute" is the same as "minutes").

Sample Nucleus component configuration:

 /path/to/TimeInterval.properties
 $class=atg.service.util.ChunkedTimeInterval
 # When class is used as a nucleus component, should use request scope only
 $scope=request
 # Create a window of three hours
 intervalCount=3
 intervalUnitName=hours
 
Then link client component's properties to this componet's startTime/endTime or startDate/endDate properties.

Created 2010-01-22


Field Summary
static java.lang.String CLASS_VERSION
           
static int FIRST_YEAR
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
ChunkedTimeInterval()
          Default constructor which will base start and end date/time values from current time
ChunkedTimeInterval(java.util.Date pBaseDate)
          Constructor with which the base date used to calculate start and end date/time values is specified.
 
Method Summary
protected  void calculate()
          Calculate, or recalculate, the start and end date/time values.
 java.util.Date getBaseDate()
          Return the Date value used to calculate the time window.
 java.util.Date getEndDate()
          Return the calculated end time of the time interval based on the specified (or default) baseDate.
 long getEndTime()
          Return the calculated end of the time interval in milliseconds.
 java.lang.String getEndTimeAsString()
          Return the calculated end time of the time interval in milliseconds, as a String.
 long getEndTimeSeconds()
          Return the calculated start time of the time interval in seconds.
 java.lang.String getEndTimeSecondsAsString()
          Return the calculated end time of the time interval in seconds as a String.
 int getIntervalCount()
          The number of 'intervalUnitName' time units for the chunk.
 java.lang.String getIntervalUnitName()
          The time interval unit name.
 long getMillisecondsUntil(java.util.Date pDate)
          Return the number of milliseconds until the specified date.
 long getMillisecondsUntilEnd()
          Return the number of milliseconds until the end date.
 java.util.Date getStartDate()
          Return the calculated start date of the time interval based on the specified (or default) baseDate.
 long getStartTime()
          Return the calculated start of the time interval in milliseconds.
 java.lang.String getStartTimeAsString()
          Return the calculated start time of the time interval in milliseconds, as a String.
 long getStartTimeSeconds()
          Return the calculated start time of the time interval in seconds.
 java.lang.String getStartTimeSecondsAsString()
          Return the calculated start date of the time interval in seconds, based on the specified (or default) baseDate, as a String.
protected  boolean isCalculationNecessary(java.util.Date pDate)
          Return true if the end date has not yet been calculated or if it has and that date has passed.
 void setBaseDate(java.util.Date pDate)
          Set the Date value used to calculate the time window.
 void setIntervalCount(int pIntervalCount)
          The number of 'intervalUnitName' time units for the chunk.
 void setIntervalUnitName(java.lang.String pUnitName)
          The time interval unit name.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST_YEAR

public static final int FIRST_YEAR
See Also:
Constant Field Values

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Constructor Detail

ChunkedTimeInterval

public ChunkedTimeInterval()
Default constructor which will base start and end date/time values from current time


ChunkedTimeInterval

public ChunkedTimeInterval(java.util.Date pBaseDate)
Constructor with which the base date used to calculate start and end date/time values is specified.

Parameters:
pBaseDate - The base date or null
Method Detail

setIntervalUnitName

public void setIntervalUnitName(java.lang.String pUnitName)
The time interval unit name.

Parameters:
pUnitName - the name of the time interval

getIntervalUnitName

public java.lang.String getIntervalUnitName()
The time interval unit name.

Returns:
the name of the time interval

setIntervalCount

public void setIntervalCount(int pIntervalCount)
The number of 'intervalUnitName' time units for the chunk.

Parameters:
pIntervalCount - a positive integer

getIntervalCount

public int getIntervalCount()
The number of 'intervalUnitName' time units for the chunk.

Returns:

getStartDate

public java.util.Date getStartDate()
Return the calculated start date of the time interval based on the specified (or default) baseDate.

Returns:
the time interval start date

getStartTime

public long getStartTime()
Return the calculated start of the time interval in milliseconds.

Returns:
the time interval start time in milliseconds

getStartTimeAsString

public java.lang.String getStartTimeAsString()
Return the calculated start time of the time interval in milliseconds, as a String.

Returns:
the start of the time interval in milliseconds, as a string

getStartTimeSeconds

public long getStartTimeSeconds()
Return the calculated start time of the time interval in seconds.

Returns:
the time interval start time in milliseconds

getStartTimeSecondsAsString

public java.lang.String getStartTimeSecondsAsString()
Return the calculated start date of the time interval in seconds, based on the specified (or default) baseDate, as a String.

Returns:
the time interval start time in milliseconds

getEndDate

public java.util.Date getEndDate()
Return the calculated end time of the time interval based on the specified (or default) baseDate.

Returns:
the time interval end date

getEndTime

public long getEndTime()
Return the calculated end of the time interval in milliseconds.

Returns:
the time interval end time in milliseconds

getEndTimeAsString

public java.lang.String getEndTimeAsString()
Return the calculated end time of the time interval in milliseconds, as a String.

Returns:
the end of the time interval in milliseconds, as a string

getEndTimeSeconds

public long getEndTimeSeconds()
Return the calculated start time of the time interval in seconds.

Returns:
the time interval start time in milliseconds

getEndTimeSecondsAsString

public java.lang.String getEndTimeSecondsAsString()
Return the calculated end time of the time interval in seconds as a String.

Returns:
the end time value as a string

getMillisecondsUntilEnd

public long getMillisecondsUntilEnd()
Return the number of milliseconds until the end date. Note that this is calculated from the current time and not from the configured baseDate. This is intended to be used for populating cache items with expiration times.

Returns:
the number of milliseconds until the end of the time window is reached. Will be a negative value if window has already passed.

getMillisecondsUntil

public long getMillisecondsUntil(java.util.Date pDate)
Return the number of milliseconds until the specified date. Note that this is calculated from the current time and not from the configured baseDate. This is intended to be used for populating cache items with expiration times.

Parameters:
pDate - a non-null date value.
Returns:
the number of milliseconds until the specified date/time is reached. Will be a negative value if window has already passed.

getBaseDate

public java.util.Date getBaseDate()
Return the Date value used to calculate the time window.

Returns:
the base date/time used for time window calculation
See Also:
setBaseDate(java.util.Date)

setBaseDate

public void setBaseDate(java.util.Date pDate)
Set the Date value used to calculate the time window. Setting this value clears any previously calculated time start/end dates as well in order to force the time window to be recalculated.

Parameters:
pDate - the base time used for time window calculation
See Also:
getBaseDate()

isCalculationNecessary

protected boolean isCalculationNecessary(java.util.Date pDate)
Return true if the end date has not yet been calculated or if it has and that date has passed.

Returns:
true if the time interval should be calculated

calculate

protected void calculate()
Calculate, or recalculate, the start and end date/time values. If the date values haven't been calculated yet, or if the end date has passed, calculate new values and update the start and end date properties.