atg.repository.search.indexing
Class ConfigStatePersister

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.repository.search.indexing.ConfigStatePersister
All Implemented Interfaces:
NameContextBindingListener, NameContextElement, NameResolver, AdminableService, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, atg.nucleus.PostStartupAction, Service, ServiceListener, java.util.EventListener

public class ConfigStatePersister
extends GenericService
implements atg.nucleus.PostStartupAction

Handles persisting information about the state of the indexing configuration. Specifically, persists such information as:

A generation is merely a version number for a set of changes. The generation mechanism exists so that the incremental loader can queue up a set of changes (see IncrementalItemQueue), claim that generation and begin processing it, even as change events get queued up in the next generation.

Created: April 15 2005


Nested Class Summary
 class ConfigStatePersister.ConfigState
          Class which represents the configuration state.
static class ConfigStatePersister.IndexingReadLockedTransactionAction
          An inner class to do a transaction with the CLAIMED read lock.
static class ConfigStatePersister.IndexingWriteLockedTransactionAction
          An inner class to do a transaction with the CLAIMED write lock.
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
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
ConfigStatePersister()
           
 
Method Summary
 int claimAndIncrementGeneration(java.lang.String pConfigPath, boolean pForIncrementalUpdate, boolean pUseConfigurationClaims, IndexingOutputConfig pIOC)
          Claim the current generation, increment the generation count, and return the number for the generation we just claimed.
 void completedFullIndex(java.lang.String pConfigPath, int pGeneration, boolean pCompletedSuccessfully, boolean pUseConfigurationClaims)
           
 void completedIncrementalIndex(java.lang.String pConfigPath, int pGeneration, boolean pCompletedSuccessfully, boolean pUseConfigurationClaims)
           
protected  void completedIndex(java.lang.String pConfigPath, int pGeneration, boolean pCompletedSuccessfully, boolean pIncremental, boolean pUseConfigurationClaims)
           
protected  ConfigStatePersister.ConfigState createConfigState(RepositoryItem pItem)
          Create a configuration state from the specified repository item.
 void doStartService()
          Start up the service...
protected  RepositoryItem[] getClaimedConfigStateItems()
          Return the configuration items claimed by some server.
 java.lang.String getClaimedGenerationPropertyName()
          Get the claimed generation property name.
 ClientLockManager getClientLockManager()
          The client lock manager...
 java.lang.String getConfigPathPropertyName()
           
protected  RepositoryItem[] getConfigStateItemsByUniqueServerId(java.lang.String pUniqueServerId)
          Return the repository items that are owned by the specified server Id.
 java.lang.Object getConfigStateProperty(java.lang.String pConfigPath, java.lang.String pPropertyName)
           
 int getCurrentGenerationForConfig(java.lang.String pConfigPath)
          Get the current generation for the specified configuration.
 int getGenerationForConfig(java.lang.String pConfigPath)
          Get the generation for the specified config.
 java.lang.String getGenerationPropertyName()
           
 atg.adapter.gsa.GSARepository getGSARepository()
          Get the repository as a GSA repository
 RepositoryItemDescriptor getItemDescriptor()
          Get the item descriptor used for storage.
 java.lang.String getItemDescriptorName()
           
protected  RepositoryItem getItemForConfig(java.lang.String pConfigPath, boolean pMutable)
          Get or create the repository item for the specified configuration.
 java.lang.String getLastActivityPropertyName()
           
 java.lang.String getLastFullIndexPropertyName()
           
 java.util.Date getLastFullIndexTime(java.lang.String pConfigPath)
          Get the last full index time.
 java.lang.String getLastIncrementalIndexPropertyName()
           
 java.util.Date getLastIncrementalIndexTime(java.lang.String pConfigPath)
          Get the last incremental index time.
 java.net.InetAddress getLocalHost()
          Returns the InetAddress of this host
 java.lang.Integer getNextIncrementalGeneration(java.lang.String pConfigPath)
          Get the next incremental generation value from the configuration record.
 java.lang.String getNextIncrementalGenerationPropertyName()
           
 long getRefreshCurrentGenerationMsecs()
          The number of seconds before cached information about the current generation for a configuration is considered stale.
 MutableRepository getRepository()
          The repository to store items.
 java.net.InetAddress getSessionIdAddress()
          Returns the IP address that will be stamped into generated session id's
 int getSessionIdPort()
          Returns the IP address that will be stamped into generated session id's
 long getTimeOutMsecs()
          Get the number of milliseconds of inactivity before a claimed index is considered timed out.
 javax.transaction.TransactionManager getTransactionManager()
          Get the transaction manager used to manager transactions.
protected  RepositoryItem[] getUnclaimedConfigStateItems()
          Return the configuration items claimed by some server.
 ConfigStatePersister.ConfigState[] getUnclaimedConfigStates()
          Get the generation for the specified config.
 java.lang.String getUniqueServerId()
          This is a uniq id for each dyanmo server.
 java.lang.String getUniqueServerIdPropertyName()
           
protected  boolean hasTimedOut(long pLastActivity)
          Whether the last activity time is considered timed out.
protected  boolean hasTimedOut(RepositoryItem pItem)
          Whether the lastActivity property on pItem is longer ago than timeOutMsecs.
 boolean isAlwaysAcquireWriteLock()
          Whether to always acquire a write lock from the lock manager.
 boolean isRequireGlobalLock()
          Whether to ensure that global locks are acquired when the ClientLockManager's useLockServer property is 'true'.
 boolean isUseConfigurationClaims()
          Whether to use configuration claims.
 void performAction()
          Called after Nuclues starts, after this point it's safe to use the ClientLockManager and get actual global locks.
 void releaseAllConfigurations()
          Release all configurations claimed by this server.
 void releaseTimedOutConfigurations()
          Release all configurations claimed by this server.
 void removedCachedValueForConfig(java.lang.String pConfigPath)
          Remove cached information for the specified configuration path, so that it will be fetched anew next time it is needed.
 void setAlwaysAcquireWriteLock(boolean pAlwaysAcquireWriteLock)
          Whether to always acquire a write lock from the lock manager.
 void setClaimedGenerationPropertyName(java.lang.String pClaimedGenerationPropertyName)
          Set the claimed generation property name.
 void setConfigPathPropertyName(java.lang.String pConfigPathPropertyName)
           
 void setGenerationPropertyName(java.lang.String pGenerationPropertyName)
           
 void setItemDescriptorName(java.lang.String pItemDescriptorName)
           
 void setLastActivityPropertyName(java.lang.String pLastActivityPropertyName)
           
 void setLastFullIndexPropertyName(java.lang.String pLastFullIndexPropertyName)
           
 void setLastIncrementalIndexPropertyName(java.lang.String pLastIncrementalIndexPropertyName)
           
protected  void setNextIncrementalGeneration(java.lang.String pConfigPath, int pGeneration)
          Set the next incremental version to a spcific value.
 void setNextIncrementalGenerationPropertyName(java.lang.String pNextIncrementalGenerationPropertyName)
           
 void setRefreshCurrentGenerationMsecs(long pRefreshCurrentGenerationMsecs)
          The number of seconds before cached information about the current generation for a configuration is considered stale.
 void setRepository(MutableRepository pRepository)
          The repository to store items.
 void setRequireGlobalLock(boolean pRequre)
          Whether to ensure that global locks are acquired when the ClientLockManager's useLockServer property is 'true'.
 void setSessionIdAddress(java.net.InetAddress pSessionIdAddress)
          Sets the IP address that will be stamped into generated session id's
 void setSessionIdPort(int pSessionIdPort)
          Sets the IP address that will be stamped into generated session id's
 void setTimeOutMsecs(long pTimeOutMsecs)
          Set the number of milliseconds of inactivity before a claimed index is considered timed out.
 void setUniqueServerIdPropertyName(java.lang.String pUniqueServerIdPropertyName)
           
 void setUseConfigurationClaims(boolean pUseConfigurationClaims)
          Whether to use configuration claims.
 void updateLastActivityTime(java.lang.String pConfigPath, int pGeneration)
          Update the activity time for the specified generation.
 void updateLastActivityTime(java.lang.String pConfigPath, int pGeneration, long pLastActivityTime)
          Update the activity time for the specified generation.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, 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

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values
Constructor Detail

ConfigStatePersister

public ConfigStatePersister()
Method Detail

setRepository

public void setRepository(MutableRepository pRepository)
The repository to store items.


getRepository

public MutableRepository getRepository()
The repository to store items.


getGSARepository

public atg.adapter.gsa.GSARepository getGSARepository()
Get the repository as a GSA repository


setItemDescriptorName

public void setItemDescriptorName(java.lang.String pItemDescriptorName)

getItemDescriptorName

public java.lang.String getItemDescriptorName()

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Get the transaction manager used to manager transactions.


getItemDescriptor

public RepositoryItemDescriptor getItemDescriptor()
Get the item descriptor used for storage.


setConfigPathPropertyName

public void setConfigPathPropertyName(java.lang.String pConfigPathPropertyName)

getConfigPathPropertyName

public java.lang.String getConfigPathPropertyName()

setGenerationPropertyName

public void setGenerationPropertyName(java.lang.String pGenerationPropertyName)

getGenerationPropertyName

public java.lang.String getGenerationPropertyName()

setUniqueServerIdPropertyName

public void setUniqueServerIdPropertyName(java.lang.String pUniqueServerIdPropertyName)

getUniqueServerIdPropertyName

public java.lang.String getUniqueServerIdPropertyName()

setLastActivityPropertyName

public void setLastActivityPropertyName(java.lang.String pLastActivityPropertyName)

getLastActivityPropertyName

public java.lang.String getLastActivityPropertyName()

setLastFullIndexPropertyName

public void setLastFullIndexPropertyName(java.lang.String pLastFullIndexPropertyName)

getLastFullIndexPropertyName

public java.lang.String getLastFullIndexPropertyName()

setLastIncrementalIndexPropertyName

public void setLastIncrementalIndexPropertyName(java.lang.String pLastIncrementalIndexPropertyName)

getLastIncrementalIndexPropertyName

public java.lang.String getLastIncrementalIndexPropertyName()

setTimeOutMsecs

public void setTimeOutMsecs(long pTimeOutMsecs)
Set the number of milliseconds of inactivity before a claimed index is considered timed out.


getTimeOutMsecs

public long getTimeOutMsecs()
Get the number of milliseconds of inactivity before a claimed index is considered timed out.


setRefreshCurrentGenerationMsecs

public void setRefreshCurrentGenerationMsecs(long pRefreshCurrentGenerationMsecs)
The number of seconds before cached information about the current generation for a configuration is considered stale.


getRefreshCurrentGenerationMsecs

public long getRefreshCurrentGenerationMsecs()
The number of seconds before cached information about the current generation for a configuration is considered stale.


setClaimedGenerationPropertyName

public void setClaimedGenerationPropertyName(java.lang.String pClaimedGenerationPropertyName)
Set the claimed generation property name.


getClaimedGenerationPropertyName

public java.lang.String getClaimedGenerationPropertyName()
Get the claimed generation property name.


setNextIncrementalGenerationPropertyName

public void setNextIncrementalGenerationPropertyName(java.lang.String pNextIncrementalGenerationPropertyName)

getNextIncrementalGenerationPropertyName

public java.lang.String getNextIncrementalGenerationPropertyName()

getUniqueServerId

public java.lang.String getUniqueServerId()
This is a uniq id for each dyanmo server. IpAddress and DprPort. (###.###.###.###:####)


getSessionIdAddress

public java.net.InetAddress getSessionIdAddress()
Returns the IP address that will be stamped into generated session id's


setSessionIdAddress

public void setSessionIdAddress(java.net.InetAddress pSessionIdAddress)
Sets the IP address that will be stamped into generated session id's


getSessionIdPort

public int getSessionIdPort()
Returns the IP address that will be stamped into generated session id's


setSessionIdPort

public void setSessionIdPort(int pSessionIdPort)
Sets the IP address that will be stamped into generated session id's


getLocalHost

public java.net.InetAddress getLocalHost()
Returns the InetAddress of this host


getClientLockManager

public ClientLockManager getClientLockManager()
The client lock manager... used to prevent multiple servers from claiming/unclaiming a configuration.


setAlwaysAcquireWriteLock

public void setAlwaysAcquireWriteLock(boolean pAlwaysAcquireWriteLock)
Whether to always acquire a write lock from the lock manager.


isAlwaysAcquireWriteLock

public boolean isAlwaysAcquireWriteLock()
Whether to always acquire a write lock from the lock manager.


setUseConfigurationClaims

public void setUseConfigurationClaims(boolean pUseConfigurationClaims)
Whether to use configuration claims. No longer necessary in general since the SearchAdmin now controlls indexing. This should mean that no two IOCs/loaders are ever given the same indexing job at once. It may be necessary to re-enable locking (by setting this to true) if indexing is not initiated by the Search Admin and especially in cases where multiple ATG instances could initiate the index process for the same configuration.

Parameters:
pUseConfigurationClaims - true to use configuration claims

isUseConfigurationClaims

public boolean isUseConfigurationClaims()
Whether to use configuration claims. No longer necessary in general since the SearchAdmin now controlls indexing. This should mean that no two IOCs/loaders are ever given the same indexing job at once. It may be necessary to re-enable locking (by setting this to true) if indexing is not initiated by the Search Admin and especially in cases where multiple ATG instances could initiate the index process for the same configuration.

Returns:
true if using configuration claiming

setRequireGlobalLock

public void setRequireGlobalLock(boolean pRequre)
Whether to ensure that global locks are acquired when the ClientLockManager's useLockServer property is 'true'. Prior to this setting the global v.s. local lock status was always ignored.

Parameters:
pRequire - true to require global lock

isRequireGlobalLock

public boolean isRequireGlobalLock()
Whether to ensure that global locks are acquired when the ClientLockManager's useLockServer property is 'true'. Prior to this setting the global v.s. local lock status was always ignored.

Returns:
true when global locks are required

getItemForConfig

protected RepositoryItem getItemForConfig(java.lang.String pConfigPath,
                                          boolean pMutable)
                                   throws RepositoryException
Get or create the repository item for the specified configuration.

Throws:
RepositoryException

getGenerationForConfig

public int getGenerationForConfig(java.lang.String pConfigPath)
                           throws IndexingException
Get the generation for the specified config. Will create a repository entry if none exists.

Throws:
IndexingException

updateLastActivityTime

public void updateLastActivityTime(java.lang.String pConfigPath,
                                   int pGeneration)
                            throws IndexingException
Update the activity time for the specified generation. The specified generation must match the currently claimed generation.

Throws:
IndexingException

updateLastActivityTime

public void updateLastActivityTime(java.lang.String pConfigPath,
                                   int pGeneration,
                                   long pLastActivityTime)
                            throws IndexingException
Update the activity time for the specified generation. The specified generation must match the currently claimed generation.

Parameters:
pConfigPath - the configuration path for the config status
pGeneration - the generation claimed whose last activity time needs to be update
pLastActivityTime - the new last activity time to be written
Throws:
IndexingException

claimAndIncrementGeneration

public int claimAndIncrementGeneration(java.lang.String pConfigPath,
                                       boolean pForIncrementalUpdate,
                                       boolean pUseConfigurationClaims,
                                       IndexingOutputConfig pIOC)
                                throws IndexingException,
                                       ConfigurationClaimedIndexingException
Claim the current generation, increment the generation count, and return the number for the generation we just claimed.

Parameters:
pConfigPath - The configuration path of the configuration to claim.
pForIncrementalUpdate -
pUseConfigurationClaims - If true, use and enforce configruation claims by throwing ConfigurationClaimedIndexingException if configuration has been claimed by another process. Otherwise, claim configuration and warn if exception would have been thrown.
Returns:
the claimed generation, or -1 if this server already claimed the configuration (presumably in a different thread).
Throws:
IndexingException
ConfigurationClaimedIndexingException

completedFullIndex

public void completedFullIndex(java.lang.String pConfigPath,
                               int pGeneration,
                               boolean pCompletedSuccessfully,
                               boolean pUseConfigurationClaims)
                        throws IndexingException
Throws:
IndexingException

completedIncrementalIndex

public void completedIncrementalIndex(java.lang.String pConfigPath,
                                      int pGeneration,
                                      boolean pCompletedSuccessfully,
                                      boolean pUseConfigurationClaims)
                               throws IndexingException
Throws:
IndexingException

getNextIncrementalGeneration

public java.lang.Integer getNextIncrementalGeneration(java.lang.String pConfigPath)
                                               throws IndexingException
Get the next incremental generation value from the configuration record.

Parameters:
pConfigPath - the configpath
Throws:
IndexingException

setNextIncrementalGeneration

protected void setNextIncrementalGeneration(java.lang.String pConfigPath,
                                            int pGeneration)
                                     throws IndexingException
Set the next incremental version to a spcific value. This is used when external indexing errors, such as SearchAdmin, indexing engine, or deployment errors, occur and it is necessary to revert to a prior generation. It is assumed that the changes in the queue for these older generations have not been deleted.

Parameters:
pConfigPath - the IOC config path
pGeneration - the new, next incremental generation number
Throws:
IndexingException

completedIndex

protected void completedIndex(java.lang.String pConfigPath,
                              int pGeneration,
                              boolean pCompletedSuccessfully,
                              boolean pIncremental,
                              boolean pUseConfigurationClaims)
                       throws IndexingException
Throws:
IndexingException

getLastFullIndexTime

public java.util.Date getLastFullIndexTime(java.lang.String pConfigPath)
                                    throws IndexingException
Get the last full index time.

Throws:
IndexingException

getLastIncrementalIndexTime

public java.util.Date getLastIncrementalIndexTime(java.lang.String pConfigPath)
                                           throws IndexingException
Get the last incremental index time.

Throws:
IndexingException

getConfigStateProperty

public java.lang.Object getConfigStateProperty(java.lang.String pConfigPath,
                                               java.lang.String pPropertyName)
                                        throws IndexingException
Throws:
IndexingException

getConfigStateItemsByUniqueServerId

protected RepositoryItem[] getConfigStateItemsByUniqueServerId(java.lang.String pUniqueServerId)
                                                        throws RepositoryException
Return the repository items that are owned by the specified server Id. This method expects a transaction already in place.

Throws:
RepositoryException

getClaimedConfigStateItems

protected RepositoryItem[] getClaimedConfigStateItems()
                                               throws RepositoryException
Return the configuration items claimed by some server. Assumes a transaction is already in place.

Throws:
RepositoryException

getUnclaimedConfigStateItems

protected RepositoryItem[] getUnclaimedConfigStateItems()
                                                 throws RepositoryException
Return the configuration items claimed by some server. Assumes a transaction is already in place.

Throws:
RepositoryException

getUnclaimedConfigStates

public ConfigStatePersister.ConfigState[] getUnclaimedConfigStates()
                                                            throws IndexingException
Get the generation for the specified config. Will create a repository entry if none exists.

Throws:
IndexingException

createConfigState

protected ConfigStatePersister.ConfigState createConfigState(RepositoryItem pItem)
Create a configuration state from the specified repository item.


hasTimedOut

protected boolean hasTimedOut(RepositoryItem pItem)
Whether the lastActivity property on pItem is longer ago than timeOutMsecs.

Parameters:
pItem - the item whose lastActivity property will be consulted to look at timeout.

hasTimedOut

protected boolean hasTimedOut(long pLastActivity)
Whether the last activity time is considered timed out.

Parameters:
pLastActivity - The last activity time expressed in milliseconds.

releaseAllConfigurations

public void releaseAllConfigurations()
                              throws IndexingException
Release all configurations claimed by this server. This method is called by doStartService().

Throws:
IndexingException

releaseTimedOutConfigurations

public void releaseTimedOutConfigurations()
                                   throws IndexingException
Release all configurations claimed by this server. This method is called by doStartService().

Throws:
IndexingException

getCurrentGenerationForConfig

public int getCurrentGenerationForConfig(java.lang.String pConfigPath)
                                  throws IndexingException
Get the current generation for the specified configuration.

Throws:
IndexingException

removedCachedValueForConfig

public void removedCachedValueForConfig(java.lang.String pConfigPath)
Remove cached information for the specified configuration path, so that it will be fetched anew next time it is needed.


doStartService

public void doStartService()
                    throws ServiceException
Start up the service...

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

performAction

public void performAction()
Called after Nuclues starts, after this point it's safe to use the ClientLockManager and get actual global locks.

Specified by:
performAction in interface atg.nucleus.PostStartupAction