atg.service.idgen
Class PersistentIdGenerator

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.idgen.AbstractSequentialIdGenerator
              extended by atg.service.idgen.PersistentIdGenerator
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, IdGenerator, java.util.EventListener
Direct Known Subclasses:
FileIdGenerator, SQLIdGenerator

public abstract class PersistentIdGenerator
extends AbstractSequentialIdGenerator
implements IdGenerator

An IdGenerator that gives out ids suitable for use with persistent objects. The ids are reserved in batches from some a persistent data store. The ids generated generally sequential and strictly increasing. A PersistentIdGenerator will not avoid ever giving out the same id twice for a given IdSpace, even across restarts of the JVM. This class reserves batches of ids from the data store and doles them out one at a time. Thus the ids given out are generally sequential and strictly increasing. Subclasses should indicate whether or not they are safe to use in a distributed system.

See Also:
IdGenerator

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
protected static java.lang.String ERR_ADD_BAD_STATE
           
protected static java.lang.String ERR_ADD_NULL_SPACE
           
protected static java.lang.String ERR_READING_BOOTSTRAP_SPACES
           
protected static int STATE_ERROR
           
protected static int STATE_INITIALIZING
           
protected static int STATE_NEW
           
protected static int STATE_RUNNING
           
protected static java.lang.String WARN_PICKING_DEFAULT
           
 
Fields inherited from class atg.service.idgen.AbstractSequentialIdGenerator
ERR_BAD_SPACE, ERR_ROLLBACK, ERR_UNSUPPORTED, mSpaces, RESOURCE_BUNDLE_NAME, sResourceBundle
 
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
PersistentIdGenerator()
           
 
Method Summary
 boolean addIdSpace(IdSpace pSpace)
          Add an id space to the id generator.
protected abstract  boolean addPersistentIdSpace(IdSpace pSpace)
          Add id space to the data store.
 atg.xml.XMLFile getInitialIdSpaces()
          Get property initialIdSpaces
 boolean getLoadInitialIdSpacesAtStartup()
          Get property loadInitialIdSpacesAtStartup.
 javax.transaction.TransactionManager getTransactionManager()
          Get property TransactionManager
 atg.xml.tools.XMLToolsFactory getXMLToolsFactory()
          Get property XMLToolsFactory
 void initialize()
          Initialize the generator.
protected abstract  void initializeIdSpaces()
          Initialize the id spaces from the data store.
 void removeAllIdSpaces()
          Remove all id spaces from the id generator.
 boolean removeIdSpace(IdSpace pSpace)
          Remove an id space from the id generator.
protected abstract  void reserveSeeds(IdSpace pSpace)
          Reserve a batch of seeds for the specified id space and update the id space itself with the new seed information.
 void setInitialIdSpaces(atg.xml.XMLFile pInitialIdSpaces)
          Set property initialIdSpaces
 void setLoadInitialIdSpacesAtStartup(boolean pLoadInitialIdSpacesAtStartup)
          Set property loadInitialIdSpacesAtStartup.
 void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)
          Set property TransactionManager
 void setXMLToolsFactory(atg.xml.tools.XMLToolsFactory pXMLToolsFactory)
          Set property XMLToolsFactory
 
Methods inherited from class atg.service.idgen.AbstractSequentialIdGenerator
doStartService, format, format, format, format, generateLongId, generateLongId, generateStringId, generateStringId, getAutoCreate, getBundle, getDefaultIdSpace, getDefaultIdSpaceName, getIdSpace, getIdSpaces, getResourceBundleName, isAutoCreate, postGenerateLongId, postGenerateStringId, setAutoCreate, setDefaultIdSpace, setDefaultIdSpaceName, setHighWaterMark, toString
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, 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, wait, wait, wait
 
Methods inherited from interface atg.service.idgen.IdGenerator
generateLongId, generateLongId, generateStringId, generateStringId, getAutoCreate, getDefaultIdSpace, getIdSpace, getIdSpaces, isAutoCreate, setAutoCreate
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


STATE_NEW

protected static int STATE_NEW

STATE_INITIALIZING

protected static int STATE_INITIALIZING

STATE_RUNNING

protected static int STATE_RUNNING

STATE_ERROR

protected static int STATE_ERROR

WARN_PICKING_DEFAULT

protected static java.lang.String WARN_PICKING_DEFAULT

ERR_READING_BOOTSTRAP_SPACES

protected static java.lang.String ERR_READING_BOOTSTRAP_SPACES

ERR_ADD_NULL_SPACE

protected static java.lang.String ERR_ADD_NULL_SPACE

ERR_ADD_BAD_STATE

protected static java.lang.String ERR_ADD_BAD_STATE
Constructor Detail

PersistentIdGenerator

public PersistentIdGenerator()
Method Detail

setTransactionManager

public void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)
Set property TransactionManager

Parameters:
pTransactionManager - new value to set

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Get property TransactionManager

Returns:
TransactionManager

setXMLToolsFactory

public void setXMLToolsFactory(atg.xml.tools.XMLToolsFactory pXMLToolsFactory)
Set property XMLToolsFactory

Parameters:
pXMLToolsFactory - new value to set

getXMLToolsFactory

public atg.xml.tools.XMLToolsFactory getXMLToolsFactory()
Get property XMLToolsFactory

Returns:
XMLToolsFactory

setInitialIdSpaces

public void setInitialIdSpaces(atg.xml.XMLFile pInitialIdSpaces)
Set property initialIdSpaces

Parameters:
pInitialIdSpaces - new value to set

getInitialIdSpaces

public atg.xml.XMLFile getInitialIdSpaces()
Get property initialIdSpaces

Returns:
initialIdSpaces

setLoadInitialIdSpacesAtStartup

public void setLoadInitialIdSpacesAtStartup(boolean pLoadInitialIdSpacesAtStartup)
Set property loadInitialIdSpacesAtStartup. This is if true the XML file specified by the initialIdSpaces property is loaded at startup. If false the XML file is only loaded when no persistent ids are found in the DB. The default is true.

Parameters:
pLoadInitialIdSpacesAtStartup - new value to set

getLoadInitialIdSpacesAtStartup

public boolean getLoadInitialIdSpacesAtStartup()
Get property loadInitialIdSpacesAtStartup. If this is true the XML file specified by the initialIdSpaces property is loaded at startup. If false the XML file is only loaded when no persistent ids are found in the DB. The default is true.

Returns:
loadInitialIdSpacesAtStartup

initialize

public void initialize()
                throws IdGeneratorException
Initialize the generator. This method must be called before attempting to generate ids. This method runs in its own transaction. Any existing transaction context is suspended and then resumed.

Specified by:
initialize in interface IdGenerator
Overrides:
initialize in class AbstractSequentialIdGenerator
Throws:
IdGeneratorException - if there is an error initializing. If initialization was unsuccessful the IdGeneratorException may have a source exception which is a chain of all of the exceptions encountered during the attempt to initialize

reserveSeeds

protected abstract void reserveSeeds(IdSpace pSpace)
                              throws IdGeneratorException
Reserve a batch of seeds for the specified id space and update the id space itself with the new seed information. This method is called when the current batch of seeds has been used up.

Parameters:
pSpace - id space to reserve seeds in, cannot be null
Throws:
IdGeneratorException - if there is a problem reserving the seeds

initializeIdSpaces

protected abstract void initializeIdSpaces()
                                    throws IdGeneratorException
Initialize the id spaces from the data store. This method is called by initialize.

Throws:
IdGeneratorException

addIdSpace

public boolean addIdSpace(IdSpace pSpace)
                   throws IdGeneratorException
Add an id space to the id generator. The id space must not be null.

Specified by:
addIdSpace in interface IdGenerator
Overrides:
addIdSpace in class AbstractSequentialIdGenerator
Parameters:
pSpace - space to add, cannot be null
Returns:
true if the space is added, or false if a space with the same name already exists in this id generator or there was a problem adding it.
Throws:
IdGeneratorException - if there is trouble adding the space

addPersistentIdSpace

protected abstract boolean addPersistentIdSpace(IdSpace pSpace)
                                         throws IdGeneratorException
Add id space to the data store. Subclasses implement this.

Parameters:
pSpace - space to add, will not be null
Throws:
IdGeneratorException

removeIdSpace

public boolean removeIdSpace(IdSpace pSpace)
                      throws IdGeneratorException
Remove an id space from the id generator. This is not yet supported for persistent id generators.

Specified by:
removeIdSpace in interface IdGenerator
Overrides:
removeIdSpace in class AbstractSequentialIdGenerator
Parameters:
pSpace - space to remove, cannot be null
Returns:
true if the space is removed, or false if it is not known to this id generator
Throws:
IdGeneratorException - not yet supported

removeAllIdSpaces

public void removeAllIdSpaces()
                       throws IdGeneratorException
Remove all id spaces from the id generator. This is not yet supported for persistent id generators.

Specified by:
removeAllIdSpaces in interface IdGenerator
Overrides:
removeAllIdSpaces in class AbstractSequentialIdGenerator
Throws:
IdGeneratorException - not yet supported