public abstract class CachedCollectionFilter extends GenericService
The interface provides the ability to write filters based on global and or personalized
variables. Each execution of the filter is provided a profile object that can be used
to vary results based on personal profile information.
When executing the filter, the caller can provide a string key (to uniquely identify the
unfiltered collection).
That key will be included as part of the complete cache key.
Caching is not allowed without the collection identifier key.
Caching can also be disabled using configuration. If cache is disabled, the filter never consults, or updates the cache.
Filter implemenations must also determine if the current context is appropriate to perform its filtering. For instance, a filter that only filters if the user's home state of MA, would not perform filtering if the user's home state was CT. This type of business logic can be implemented in the shouldApplyFilter method, which is called prior to looking up results in the cache or generating a new filtered collection.
The filtered collection results is a mutable collection. If cache is enabled, adding or removing objects from the returned filtered collection will change the results in the cache. Subsequent requests to the filter using the same collection identifier key will result in returning the modified filtered collection.
generateContextKey(java.util.Collection, java.lang.String, atg.repository.RepositoryItem)
,
shouldApplyFilter(java.util.Collection, java.lang.String, atg.repository.RepositoryItem)
,
isCacheEnabled()
,
generateFilteredCollection(java.util.Collection, java.lang.String, atg.repository.RepositoryItem)
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CLASS_VERSION |
static java.lang.String |
FILTER_CACHE_COMPONENT |
protected Cache |
mCache |
protected boolean |
mCacheEnabled |
SERVICE_INFO_KEY
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
CachedCollectionFilter() |
Modifier and Type | Method and Description |
---|---|
void |
dumpCache()
This method will dump the filter cache to the system console.
|
java.util.Collection |
filterCollection(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile) |
java.util.Collection |
filterCollection(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
boolean pConsultCache,
boolean pUpdateCache)
Called to create a filtered version of the unfiltered collection.
|
java.util.Collection |
filterCollection(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
boolean pConsultCache,
boolean pUpdateCache,
java.util.Map pExtraParameters)
Called to create a filtered version of the unfiltered collection.
|
java.util.Collection |
filterCollection(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
java.util.Map pExtraParameters) |
void |
flushCache()
This method will flush the filter cache if there is one configured.
|
protected CollectionCacheKey |
generateCacheKey(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile)
This method is called by the filterCollection method to create the CollectionCacheKey
object used for cache lookup and update.
|
protected CollectionCacheKey |
generateCacheKey(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
java.util.Map pExtraParameters)
This method is called by the filterCollection method to create the CollectionCacheKey
object used for cache lookup and update.
|
java.lang.Object |
generateContextKey(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile)
Generates a context key object that will be included as part of the cache key.
|
java.lang.Object |
generateContextKey(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
java.util.Map pExtraParameters)
Generates a context key object that will be included as part of the cache key.
|
protected java.util.Collection |
generateFilteredCollection(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile)
Called by the filterCollection method to generate the filtered collection.
|
protected java.util.Collection |
generateFilteredCollection(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
java.util.Map pExtraParameters)
Called by the filterCollection method to generate the filtered collection.
|
protected java.util.Collection |
generateNewCollectionObject(java.util.Collection pUnfilteredCollection)
This method creates a new collection object of same base type
as the unfiltered collection.
|
Cache |
getCache()
Returns the results cache for this filter
|
protected RepositoryItem |
getDefaultProfile()
This method is called by the filterCollection method when a profile item
is not provided by the caller.
|
boolean |
isCacheEnabled()
Returns if caching is enabled.
|
void |
setCache(Cache pCache)
Sets the results cache
|
void |
setCacheEnabled(boolean pCacheEnabled)
Sets if caching is enabled
|
boolean |
shouldApplyFilter(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile)
This method is called by filterCollection prior to looking up the filtered collection in the
cache or generating a new filtered collection.
|
boolean |
shouldApplyFilter(java.util.Collection pUnfilteredCollection,
java.lang.String pCollectionIdentifierKey,
RepositoryItem pProfile,
java.util.Map pExtraParameters)
This method is called by filterCollection prior to looking up the filtered collection in the
cache or generating a new filtered collection.
|
protected static java.lang.String |
stringIt(java.util.Collection pObject) |
addLogListener, createAdminServlet, doStartService, 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
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
public static final java.lang.String CLASS_VERSION
public static final java.lang.String FILTER_CACHE_COMPONENT
protected Cache mCache
protected boolean mCacheEnabled
public Cache getCache()
This will default to the component specified by FILTER_CACHE_COMPONENT.
FILTER_CACHE_COMPONENT
public void setCache(Cache pCache)
public boolean isCacheEnabled()
This method will return false if the filter does not have a cache component configured.
public void setCacheEnabled(boolean pCacheEnabled)
protected java.util.Collection generateNewCollectionObject(java.util.Collection pUnfilteredCollection) throws FilterException
Default collections types are used for types that can not be instantiated: ArrayList for instances of List and HashSet for instances of Set. E.g. classes that can not be instantiated directly:
pUnfilteredCollection
- the unfiltered collectionFilterException
- If a new collection object can not be instantiated
or filter does not have access to its constructors.public java.lang.Object generateContextKey(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
For instance, a filter that creates results relative to the current date might return a date object representing today's date. Or a filter that creates results relative to gender, might return a string object of "M" of "F", depending on the current profile's gender.
Objects returned by this method will be included in the key used for cache lookup. Therefore, they should implement a hashCode and equals method when appropriate.
A null value is a valid return value for filters that don't require a specific context.
public java.lang.Object generateContextKey(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, java.util.Map pExtraParameters)
For instance, a filter that creates results relative to the current date might return a date object representing today's date. Or a filter that creates results relative to gender, might return a string object of "M" of "F", depending on the current profile's gender.
Objects returned by this method will be included in the key used for cache lookup. Therefore, they should implement a hashCode and equals method when appropriate.
A null value is a valid return value for filters that don't require a specific context.
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key that was passed to the filterCollection
method.pProfile
- the user profilepExtraParameters
- map containing key-value pairs with extra parametersprotected java.util.Collection generateFilteredCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile) throws FilterException
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key that was passed to the filterCollection
method.pProfile
- Repository itemFilterException
protected java.util.Collection generateFilteredCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, java.util.Map pExtraParameters) throws FilterException
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key that was passed to the filterCollection
method.pExtraParameters
- map containing key-value pairs with extra parametersFilterException
public boolean shouldApplyFilter(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key param as passed to filterCollectionpProfile
- the user profilefilterCollection(java.util.Collection, java.lang.String, atg.repository.RepositoryItem, boolean, boolean)
public boolean shouldApplyFilter(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, java.util.Map pExtraParameters)
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key param as passed to filterCollectionpProfile
- the user profilepExtraParameters
- key-value pairs with extra parametersfilterCollection(java.util.Collection, java.lang.String, atg.repository.RepositoryItem, boolean, boolean)
protected CollectionCacheKey generateCacheKey(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile)
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key that is was provided on the call to filterCollectionpProfile
- the profile repository item.generateContextKey(java.util.Collection, java.lang.String, atg.repository.RepositoryItem)
,
CollectionCacheKey
protected CollectionCacheKey generateCacheKey(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, java.util.Map pExtraParameters)
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the key that is was provided on the call to filterCollectionpProfile
- the profile repository item.pExtraParameters
- key-value pairs with extra parametersgenerateContextKey(java.util.Collection, java.lang.String, atg.repository.RepositoryItem)
,
CollectionCacheKey
protected RepositoryItem getDefaultProfile()
public java.util.Collection filterCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, boolean pConsultCache, boolean pUpdateCache) throws FilterException
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the string that uniquely identifies the unfilterd collection. This string
will be included as part of the complete key for cache lookup.pProfile
- the profile repository item.pConsultCache
- if true the cache is first consulted for filtered resultspUpdateCache
- if true the cache is updated with the new filtered collection.FilterException
public java.util.Collection filterCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, boolean pConsultCache, boolean pUpdateCache, java.util.Map pExtraParameters) throws FilterException
pUnfilteredCollection
- the unfiltered collectionpCollectionIdentifierKey
- the string that uniquely identifies the unfilterd collection. This string
will be included as part of the complete key for cache lookup.pProfile
- the profile repository item.pConsultCache
- if true the cache is first consulted for filtered resultspUpdateCache
- if true the cache is updated with the new filtered collection.pExtraParameters
- key-value pairs with extra parametersFilterException
public java.util.Collection filterCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile) throws FilterException
public java.util.Collection filterCollection(java.util.Collection pUnfilteredCollection, java.lang.String pCollectionIdentifierKey, RepositoryItem pProfile, java.util.Map pExtraParameters) throws FilterException
protected static java.lang.String stringIt(java.util.Collection pObject)
public void flushCache()
Cache.flush()
public void dumpCache()
Cache.dump(java.io.PrintStream)