org.apache.jcs.utils.key
Class KeyGeneratorUtil

java.lang.Object
  extended by org.apache.jcs.utils.key.KeyGeneratorUtil

public final class KeyGeneratorUtil
extends Object

This can create and parse request ids. You can use it to generate keys that contain a create time stamp.

You can set a system property called "KEY_LEAD_NUMBER" to override the lead number. The value must be a simple int from 1 to 9.


Field Summary
protected static long counterResetIntervalMillis
          How often should we reset the counter.
static int DEFAULT_LEAD_NUMBER
          The default lead number.
static String KEY_LEAD_NUMBER_PROPERTY_NAME
          The name of the system property that can be used to override the default.
protected static int leadNumber
          We lead with a number so it can be converted to a number.
 
Constructor Summary
KeyGeneratorUtil()
           
 
Method Summary
static String generateRequestId()
          Creates a query id in the format 1001010121712345 where the first 8 digits (10010101) is a 8 digit number where: 1 is a padding digit and 001 is the first day of the year.
static Date getDateOfShopFromRequestId(String queryId)
          This DddHHmm.
protected static int getNextRequestCounter()
          Automatically increment and return the request counter.
protected static void resetCounter()
          reset the counter and the reset time.
protected static void setLeadFromSystemProperty()
          Sets the lead number from a system property
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

counterResetIntervalMillis

protected static long counterResetIntervalMillis
How often should we reset the counter.


KEY_LEAD_NUMBER_PROPERTY_NAME

public static final String KEY_LEAD_NUMBER_PROPERTY_NAME
The name of the system property that can be used to override the default. This allows us to run multiple instance on a machine.

See Also:
Constant Field Values

DEFAULT_LEAD_NUMBER

public static final int DEFAULT_LEAD_NUMBER
The default lead number.

See Also:
Constant Field Values

leadNumber

protected static int leadNumber
We lead with a number so it can be converted to a number. This is the prefix to all ids.

Constructor Detail

KeyGeneratorUtil

public KeyGeneratorUtil()
Method Detail

setLeadFromSystemProperty

protected static void setLeadFromSystemProperty()
Sets the lead number from a system property


generateRequestId

public static String generateRequestId()
Creates a query id in the format 1001010121712345 where the first 8 digits (10010101) is a 8 digit number where: 1 is a padding digit and 001 is the first day of the year. The next 3 digits (217) are the decimal representation of the last byte of data in the machine ip (for example 192.168.1.2 will be 002). The remaining digits (ex. 12345) are some unique number. These come from a counter that is reset every 2 hours.

Returns:
long

getDateOfShopFromRequestId

public static Date getDateOfShopFromRequestId(String queryId)
                                       throws ParseException
This DddHHmm.

This has to get the current year and set it, since the source data does not have the year.

Parameters:
queryId - queryId
Returns:
now if we can't parse, else the data from the query id.
Throws:
ParseException - ParseException

getNextRequestCounter

protected static int getNextRequestCounter()
Automatically increment and return the request counter. If the last counter reset was more than the interval, reset the counter.

Returns:
The incremented count.

resetCounter

protected static void resetCounter()
reset the counter and the reset time.



Copyright © 2002-2012 Apache Software Foundation. All Rights Reserved.