atg.service.idgen
Class FileIdGenerator

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
                  extended by atg.service.idgen.FileIdGenerator
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

public class FileIdGenerator
extends PersistentIdGenerator

PersistentIdGenerator that stores IdSpaces in a flat file as a serialized Map. This implementation is not suitable for distributed systems.

This implementation is intended for use in applications that desire simple persistent ids but do not need the transactional features of a database. For example, a file logger may associate ids with log entries. The file logger needs the ids to be unique across JVM restarts, however it does not need to share these ids with loggers in other JVMs.

Different applications can use a single instance of the file id generator. Different file id generators must not use the same data file.

No file locking is attempted. The flat file should not be modified by any other facility, nor should it be read while it is in use.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.service.idgen.PersistentIdGenerator
ERR_ADD_BAD_STATE, ERR_ADD_NULL_SPACE, ERR_READING_BOOTSTRAP_SPACES, STATE_ERROR, STATE_INITIALIZING, STATE_NEW, STATE_RUNNING, 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
FileIdGenerator()
           
 
Method Summary
protected  boolean addPersistentIdSpace(IdSpace pSpace)
          Add an id space to the data store.
 java.io.File getDataFile()
          Get property dataFile.
 void initialize()
          Initialize the id generator mgkmgk: need to override this as we do not want a transaction manager may need to factor the initialize in our parent...bleh
protected  void initializeIdSpaces()
          Initialize the id spaces from the data store.
 boolean isMakeDirs()
          Returns whether or not the parent directories of the data file should be created if they don't exist.
protected  void reserveSeeds(IdSpace pSpace)
          Reserve a batch of seeds for the specified id space from the persistent store.
 void setDataFile(java.io.File pDataFile)
          Set property dataFile.
 void setMakeDirs(boolean pMakeDirs)
          Sets whether or not the parent directories of the data file should be created if they don't exist.
 
Methods inherited from class atg.service.idgen.PersistentIdGenerator
addIdSpace, getInitialIdSpaces, getLoadInitialIdSpacesAtStartup, getTransactionManager, getXMLToolsFactory, removeAllIdSpaces, removeIdSpace, setInitialIdSpaces, setLoadInitialIdSpacesAtStartup, setTransactionManager, setXMLToolsFactory
 
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

Constructor Detail

FileIdGenerator

public FileIdGenerator()
Method Detail

setDataFile

public void setDataFile(java.io.File pDataFile)
Set property dataFile. This is the file to hold the persistent state of this id generator.

Parameters:
pDataFile - new value to set

getDataFile

public java.io.File getDataFile()
Get property dataFile. This is the file to hold the persistent state of this id generator.

Returns:
dataFile

isMakeDirs

public boolean isMakeDirs()
Returns whether or not the parent directories of the data file should be created if they don't exist.

Returns:
the makeDirs True if the directories should be created. False otherwise.

setMakeDirs

public void setMakeDirs(boolean pMakeDirs)
Sets whether or not the parent directories of the data file should be created if they don't exist.

Parameters:
pMakeDirs - the makeDirs to set

initialize

public void initialize()
                throws IdGeneratorException
Initialize the id generator mgkmgk: need to override this as we do not want a transaction manager may need to factor the initialize in our parent...bleh

Specified by:
initialize in interface IdGenerator
Overrides:
initialize in class PersistentIdGenerator
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

initializeIdSpaces

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

Specified by:
initializeIdSpaces in class PersistentIdGenerator
Throws:
IdGeneratorException - if there is a problem

addPersistentIdSpace

protected boolean addPersistentIdSpace(IdSpace pSpace)
                                throws IdGeneratorException
Add an id space to the data store. This should only be called from addIdSpace().

Specified by:
addPersistentIdSpace in class PersistentIdGenerator
Parameters:
pSpace - space to add, cannot be null. Nota Bene: this may be modified by this method.
Returns:
true if the space is added, or false if a space with the same name already exists in this id generator
Throws:
IdGeneratorException - if there is trouble adding id space

reserveSeeds

protected void reserveSeeds(IdSpace pSpace)
                     throws IdGeneratorException
Reserve a batch of seeds for the specified id space from the persistent store.

Specified by:
reserveSeeds in class PersistentIdGenerator
Parameters:
pSpace - space in which to reserve seeds, must not be null
Throws:
IdGeneratorException - if there is a problem with the persistent store