org.apache.commons.id.random
Class SessionIdGenerator

java.lang.Object
  extended by org.apache.commons.id.AbstractStringIdentifierGenerator
      extended by org.apache.commons.id.random.SessionIdGenerator
All Implemented Interfaces:
java.io.Serializable, IdentifierGenerator, StringIdentifierGenerator

public class SessionIdGenerator
extends AbstractStringIdentifierGenerator
implements java.io.Serializable

SessionIdGenerator is an identifier generator that generates an alphanumeric 10+ character identifier.

The exact length depends on the number of ids requested per time period. Multiple instances of the class generate still unique ids.

Originally designed for JServ sessions. Uses synchronized count and time to ensure uniqueness. Not guaranteed unique across JVMs, but fairly safe nonetheless.

Version:
$Id: SessionIdGenerator.java 480488 2006-11-29 08:57:26Z bayard $
Author:
Commons-Id team
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.id.AbstractStringIdentifierGenerator
ALPHA_NUMERIC_CHARSET_SIZE, DEFAULT_ALPHANUMERIC_IDENTIFIER_SIZE, MAX_INT_ALPHANUMERIC_VALUE_LENGTH, MAX_INT_NUMERIC_VALUE_LENGTH, MAX_LONG_ALPHANUMERIC_VALUE_LENGTH, MAX_LONG_NUMERIC_VALUE_LENGTH
 
Fields inherited from interface org.apache.commons.id.StringIdentifierGenerator
INFINITE_MAX_LENGTH
 
Constructor Summary
SessionIdGenerator()
          Constructor.
 
Method Summary
 long maxLength()
          Returns the maximum length (number or characters) for an identifier from this sequence.
 long minLength()
          Returns the minimum length (number of characters) for an identifier from this sequence.
 java.lang.String nextStringIdentifier()
          Gets the next new identifier.
 
Methods inherited from class org.apache.commons.id.AbstractStringIdentifierGenerator
nextIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionIdGenerator

public SessionIdGenerator()
Constructor.

Method Detail

maxLength

public long maxLength()
Description copied from class: AbstractStringIdentifierGenerator
Returns the maximum length (number or characters) for an identifier from this sequence.

The default implementation returns StringIdentifierGenerator.INFINITE_MAX_LENGTH. Implementations with bounded length identifiers should override this method to return the maximum length of a generated identifier.

Specified by:
maxLength in interface StringIdentifierGenerator
Overrides:
maxLength in class AbstractStringIdentifierGenerator
Returns:
the maximum identifier length, or StringIdentifierGenerator.INFINITE_MAX_LENGTH if there is no upper bound

minLength

public long minLength()
Description copied from class: AbstractStringIdentifierGenerator
Returns the minimum length (number of characters) for an identifier from this sequence.

The default implementation returns 0. Implementations with identifiers having a postive minimum length should override this method to return the maximum length of a generated identifier.

Specified by:
minLength in interface StringIdentifierGenerator
Overrides:
minLength in class AbstractStringIdentifierGenerator
Returns:
the minimum identifier length

nextStringIdentifier

public java.lang.String nextStringIdentifier()
Gets the next new identifier.

Only guaranteed unique within this JVM, but fairly safe for cross JVM usage as well.

Format of identifier is [6 chars random][3 chars time][1+ chars count]

Specified by:
nextStringIdentifier in interface StringIdentifierGenerator
Specified by:
nextStringIdentifier in class AbstractStringIdentifierGenerator
Returns:
the next 10 char String identifier


Copyright © 2003-2008 The Apache Software Foundation. All Rights Reserved.